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 }