From 358c4f0211bf3f7b5ab305fed7efcb606787c24e Mon Sep 17 00:00:00 2001 From: Valentin Boettcher Date: Thu, 21 Feb 2019 00:42:40 +0100 Subject: [PATCH] Add .stop hook. --- lib/namedQuery/namedQuery.client.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/namedQuery/namedQuery.client.js b/lib/namedQuery/namedQuery.client.js index 3e6b851..adafa50 100755 --- a/lib/namedQuery/namedQuery.client.js +++ b/lib/namedQuery/namedQuery.client.js @@ -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;