2017-12-17 17:42:06 +09:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-09-12 13:20:40 +02:00
|
|
|
import { registerComponent, runCallbacks, runCallbacksAsync } from 'meteor/vulcan:lib';
|
2017-12-17 17:42:06 +09:00
|
|
|
import { withApollo } from 'react-apollo';
|
|
|
|
|
|
|
|
class RouterHook extends PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-12-17 20:59:26 +09:00
|
|
|
this.runOnUpdateCallback(props);
|
2017-12-17 17:42:06 +09:00
|
|
|
}
|
2017-12-17 20:59:26 +09:00
|
|
|
|
2018-09-12 13:20:40 +02:00
|
|
|
componentDidUpdate(nextProps) {
|
|
|
|
this.runOnUpdateCallback(this.props, nextProps);
|
2017-12-17 20:59:26 +09:00
|
|
|
}
|
|
|
|
|
2018-09-12 13:20:40 +02:00
|
|
|
runOnUpdateCallback = (props, nextProps = {}) => {
|
2017-12-17 20:59:26 +09:00
|
|
|
const { currentRoute, client } = props;
|
2017-12-17 17:42:06 +09:00
|
|
|
// 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);
|
2018-09-12 13:20:40 +02:00
|
|
|
|
|
|
|
runCallbacksAsync('router.onUpdate.async', props, nextProps);
|
2017-12-17 20:59:26 +09:00
|
|
|
};
|
|
|
|
|
2017-12-17 17:42:06 +09:00
|
|
|
render() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
registerComponent('RouterHook', RouterHook, withApollo);
|