mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Merge branch 'master' into devel
This commit is contained in:
commit
1e7ae073a9
4 changed files with 36 additions and 28 deletions
|
@ -8,14 +8,11 @@ import { addCallback, getActions } from 'meteor/vulcan:lib';
|
|||
|
||||
/**
|
||||
* @summary Clear flash messages marked as seen when the route changes
|
||||
* @param {Object} Item needed by `runCallbacks` to iterate on, unused here
|
||||
* @param {Object} Redux store reference instantiated on the current connected client
|
||||
* @param {Object} Apollo Client reference instantiated on the current connected client
|
||||
* @param {Object} props
|
||||
* @param {Object} props.client Apollo Client reference instantiated on the current connected client
|
||||
*/
|
||||
function RouterClearMessages(unusedItem, nextRoute, store, apolloClient) {
|
||||
store.dispatch(getActions().messages.clearSeen());
|
||||
|
||||
return unusedItem;
|
||||
function RouterClearMessages({ client }) {
|
||||
client.store.dispatch(getActions().messages.clearSeen());
|
||||
}
|
||||
|
||||
addCallback('router.onUpdate', RouterClearMessages);
|
||||
addCallback('router.onUpdate.async', RouterClearMessages);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import React, { PureComponent } from 'react';
|
||||
import { registerComponent, runCallbacks } from 'meteor/vulcan:lib';
|
||||
import { registerComponent, runCallbacks, runCallbacksAsync } from 'meteor/vulcan:lib';
|
||||
import { withApollo } from 'react-apollo';
|
||||
|
||||
class RouterHook extends PureComponent {
|
||||
|
@ -8,15 +8,17 @@ class RouterHook extends PureComponent {
|
|||
this.runOnUpdateCallback(props);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.runOnUpdateCallback(nextProps);
|
||||
componentDidUpdate(nextProps) {
|
||||
this.runOnUpdateCallback(this.props, nextProps);
|
||||
}
|
||||
|
||||
runOnUpdateCallback = props => {
|
||||
runOnUpdateCallback = (props, nextProps = {}) => {
|
||||
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);
|
||||
|
||||
runCallbacksAsync('router.onUpdate.async', props, nextProps);
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -37,7 +37,7 @@ export const addIdentifyFunction = f => {
|
|||
};
|
||||
|
||||
export const addPageFunction = f => {
|
||||
const f2 = (empty, route) => f(route);
|
||||
const f2 = ({ currentRoute }) => f(currentRoute);
|
||||
|
||||
// rename f2 to same name as f
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
|
||||
|
@ -45,5 +45,5 @@ export const addPageFunction = f => {
|
|||
descriptor.value = f.name;
|
||||
Object.defineProperty(f2, 'name', descriptor);
|
||||
|
||||
addCallback('router.onUpdate', f2);
|
||||
addCallback('router.onUpdate.async', f2);
|
||||
};
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
|
||||
import { debug } from './debug.js';
|
||||
import { Utils } from './utils';
|
||||
|
||||
|
@ -182,17 +184,24 @@ export const runCallbacksAsync = function () {
|
|||
|
||||
const callbacks = Array.isArray(hook) ? hook : Callbacks[hook];
|
||||
|
||||
if (Meteor.isServer && typeof callbacks !== 'undefined' && !!callbacks.length) {
|
||||
if (typeof callbacks !== 'undefined' && !!callbacks.length) {
|
||||
const _runCallbacksAsync = () =>
|
||||
Promise.all(
|
||||
callbacks.map(callback => {
|
||||
debug(`\x1b[32m>> Running async callback [${callback.name}] on hook [${hook}]\x1b[0m`);
|
||||
return callback.apply(this, args);
|
||||
}),
|
||||
);
|
||||
|
||||
// use defer to avoid holding up client
|
||||
Meteor.defer(function () {
|
||||
// run all post submit server callbacks on post object successively
|
||||
callbacks.forEach(function (callback) {
|
||||
debug(`\x1b[32m>> Running async callback [${callback.name}] on hook [${hook}]\x1b[0m`);
|
||||
callback.apply(this, args);
|
||||
if (Meteor.isServer) {
|
||||
// TODO: find out if we can safely use promises on the server, too - https://github.com/VulcanJS/Vulcan/pull/2065
|
||||
return new Promise(async (resolve, reject) => {
|
||||
Meteor.defer(function() {
|
||||
_runCallbacksAsync().then(resolve).catch(reject);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
return _runCallbacksAsync();
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
Loading…
Add table
Reference in a new issue