mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -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 {
|
class RouterHook extends PureComponent {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
const { currentRoute, client } = props;
|
this.runOnUpdateCallback(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
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
|
// 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
|
// note: this item is not used in this specific callback: router.onUpdate
|
||||||
runCallbacks('router.onUpdate', {}, currentRoute, client.store, client);
|
runCallbacks('router.onUpdate', {}, currentRoute, client.store, client);
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return null;
|
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 trackFunctions = [];
|
||||||
|
|
||||||
export const addInitFunction = func => {
|
export const addInitFunction = f => {
|
||||||
initFunctions.push(func);
|
initFunctions.push(f);
|
||||||
// execute init function as soon as possible
|
// execute init function as soon as possible
|
||||||
func();
|
f();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addTrackFunction = func => {
|
export const addTrackFunction = f => {
|
||||||
trackFunctions.push(func);
|
trackFunctions.push(f);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const track = (eventName, eventProperties) => {
|
export const track = (eventName, eventProperties) => {
|
||||||
|
@ -20,10 +20,18 @@ export const track = (eventName, eventProperties) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addIdentifyFunction = func => {
|
export const addIdentifyFunction = f => {
|
||||||
addCallback('events.identify', func);
|
addCallback('events.identify', f);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addPageFunction = func => {
|
export const addPageFunction = f => {
|
||||||
addCallback('router.onUpdate', (empty, route) => func(route));
|
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';
|
export * from './events';
|
|
@ -87,7 +87,7 @@ export const runCallbacks = function () {
|
||||||
|
|
||||||
if (typeof result === 'undefined') {
|
if (typeof result === 'undefined') {
|
||||||
// if result of current iteration is undefined, don't pass it on
|
// 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
|
return accumulator
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Reference in a new issue