Add .stop hook.

This commit is contained in:
Valentin Boettcher 2019-02-21 00:42:40 +01:00
parent 43008c63a2
commit 358c4f0211

View file

@ -21,10 +21,27 @@ export default class extends Base {
throw new Meteor.Error('not-allowed', `You cannot subscribe to a resolver query`);
}
let options = {};
if(typeof callback === 'function') {
options.onReady = callback;
} else if(callback && callback.onReady || callback.onStop) {
options = callback;
}
// integrate the onStop hook
const oldStop = options.onStop;
options.onStop = (...args) => {
this.subscriptionHandle = null;
if(oldStop) {
oldStop.apply(this, args);
}
};
this.subscriptionHandle = subscriptionContext.subscribe(
this.name,
this.params,
callback
options
);
return this.subscriptionHandle;