From 51590c83fec0ebbcbb3521bc54d276f855289e87 Mon Sep 17 00:00:00 2001 From: Joel Mandell Date: Sat, 7 Sep 2019 16:56:04 +0200 Subject: [PATCH] feat: Reactive pollInterval. (#613) closes #453 * Enhancement Akryum#453 Reactive pollInterval. * Small change for pollInterval enhancement #453 * Remove unnecessary if-check in pollIntervalChanged --- src/smart-apollo.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/smart-apollo.js b/src/smart-apollo.js index cc1df16..45c3bdb 100644 --- a/src/smart-apollo.js +++ b/src/smart-apollo.js @@ -10,6 +10,7 @@ export default class SmartApollo { this.initialOptions = options this.options = Object.assign({}, options) this._skip = false + this._pollInterval = null this._watchers = [] this._destroyed = false @@ -29,6 +30,22 @@ export default class SmartApollo { } else { this._skip = true } + + if(typeof this.options.pollInterval === 'function') { + this._pollWatcher = this.vm.$watch(this.options.pollInterval.bind(this.vm),this.pollIntervalChanged.bind(this), {immediate:true}) + } + } + + pollIntervalChanged (value, oldValue) { + if (value !== oldValue) { + this.pollInterval = value + + if(value == null) { + this.stopPolling() + } else { + this.startPolling(value) + } + } } skipChanged (value, oldValue) { @@ -37,6 +54,14 @@ export default class SmartApollo { } } + get pollInterval() { + return this._pollInterval + } + + set pollInterval(value) { + this._pollInterval = value + } + get skip () { return this._skip }