mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 17:41:43 -05:00
Create new events-internal package to hold internal Mongo event tracking code
This commit is contained in:
parent
4d55c2f788
commit
104b630448
13 changed files with 64 additions and 18 deletions
|
@ -5,18 +5,20 @@ import { withApollo } from 'react-apollo';
|
|||
class RouterHook extends PureComponent {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { currentRoute, client } = props;
|
||||
console.log(props)
|
||||
// the first argument is an item to iterate on, needed by vulcan:lib/callbacks
|
||||
// note: this item is not used in this specific callback: router.onUpdate
|
||||
runCallbacks('router.onUpdate', {}, currentRoute, client.store, client);
|
||||
this.runOnUpdateCallback(props);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const { currentRoute, client } = nextProps;
|
||||
this.runOnUpdateCallback(nextProps);
|
||||
}
|
||||
|
||||
runOnUpdateCallback = props => {
|
||||
const { currentRoute, client } = props;
|
||||
// the first argument is an item to iterate on, needed by vulcan:lib/callbacks
|
||||
// note: this item is not used in this specific callback: router.onUpdate
|
||||
runCallbacks('router.onUpdate', {}, currentRoute, client.store, client);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
|
|
1
packages/vulcan-events-internal/README.md
Normal file
1
packages/vulcan-events-internal/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Vulcan events package, used internally.
|
12
packages/vulcan-events-internal/lib/client/internal.js
Normal file
12
packages/vulcan-events-internal/lib/client/internal.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { addTrackFunction } from 'meteor/vulcan:events';
|
||||
import { ApolloClient } from 'apollo-client';
|
||||
import { getRenderContext } from 'meteor/vulcan:lib';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
function trackInternal() {
|
||||
const { apolloClient, store } = getRenderContext();
|
||||
console.log(apolloClient)
|
||||
apolloClient.query({ query: gql`{ hello }` }).then(console.log);
|
||||
}
|
||||
|
||||
addTrackFunction(trackInternal);
|
3
packages/vulcan-events-internal/lib/client/main.js
Normal file
3
packages/vulcan-events-internal/lib/client/main.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
export * from '../modules/index.js';
|
||||
|
||||
import './internal.js';
|
1
packages/vulcan-events-internal/lib/modules/index.js
Normal file
1
packages/vulcan-events-internal/lib/modules/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './collection.js';
|
1
packages/vulcan-events-internal/lib/server/main.js
Normal file
1
packages/vulcan-events-internal/lib/server/main.js
Normal file
|
@ -0,0 +1 @@
|
|||
export * from '../modules/index.js';
|
0
packages/vulcan-events-internal/lib/server/mutations.js
Normal file
0
packages/vulcan-events-internal/lib/server/mutations.js
Normal file
19
packages/vulcan-events-internal/package.js
Normal file
19
packages/vulcan-events-internal/package.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
Package.describe({
|
||||
name: "vulcan:events-internal",
|
||||
summary: "Vulcan internal event tracking package",
|
||||
version: '1.8.0',
|
||||
git: "https://github.com/VulcanJS/Vulcan.git"
|
||||
});
|
||||
|
||||
Package.onUse(function(api) {
|
||||
|
||||
api.versionsFrom('METEOR@1.5.2');
|
||||
|
||||
api.use([
|
||||
'vulcan:core@1.8.0',
|
||||
]);
|
||||
|
||||
api.mainModule("lib/server/main.js", "server");
|
||||
api.mainModule('lib/client/main.js', 'client');
|
||||
|
||||
});
|
|
@ -4,14 +4,14 @@ export const initFunctions = [];
|
|||
|
||||
export const trackFunctions = [];
|
||||
|
||||
export const addInitFunction = func => {
|
||||
initFunctions.push(func);
|
||||
export const addInitFunction = f => {
|
||||
initFunctions.push(f);
|
||||
// execute init function as soon as possible
|
||||
func();
|
||||
f();
|
||||
};
|
||||
|
||||
export const addTrackFunction = func => {
|
||||
trackFunctions.push(func);
|
||||
export const addTrackFunction = f => {
|
||||
trackFunctions.push(f);
|
||||
};
|
||||
|
||||
export const track = (eventName, eventProperties) => {
|
||||
|
@ -20,10 +20,18 @@ export const track = (eventName, eventProperties) => {
|
|||
});
|
||||
}
|
||||
|
||||
export const addIdentifyFunction = func => {
|
||||
addCallback('events.identify', func);
|
||||
export const addIdentifyFunction = f => {
|
||||
addCallback('events.identify', f);
|
||||
};
|
||||
|
||||
export const addPageFunction = func => {
|
||||
addCallback('router.onUpdate', (empty, route) => func(route));
|
||||
export const addPageFunction = f => {
|
||||
const f2 = (empty, route) => f(route);
|
||||
|
||||
// rename f2 to same name as f
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
|
||||
const descriptor = Object.create(null); // no inherited properties
|
||||
descriptor.value = f.name;
|
||||
Object.defineProperty(f2, 'name', descriptor)
|
||||
|
||||
addCallback('router.onUpdate', f2);
|
||||
};
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
export * from './collection.js';
|
||||
export * from './events';
|
|
@ -87,7 +87,7 @@ export const runCallbacks = function () {
|
|||
|
||||
if (typeof result === 'undefined') {
|
||||
// if result of current iteration is undefined, don't pass it on
|
||||
console.log(`// Warning: Sync callback [${callback.name}] in hook [${hook}] didn't return a result!`)
|
||||
debug(`// Warning: Sync callback [${callback.name}] in hook [${hook}] didn't return a result!`)
|
||||
return accumulator
|
||||
} else {
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue