Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/smart-apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,6 +30,28 @@ 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 oldValue is undefined, then apollo object is 'initialized'.
if(typeof oldValue === 'undefined' && value !== null) {
this.startPolling(value)
return
}

if (value !== oldValue) {
this.pollInterval = value

if(value == null) {
this.stopPolling()
} else {
this.startPolling(value)
}
}
}

skipChanged (value, oldValue) {
Expand All @@ -37,6 +60,14 @@ export default class SmartApollo {
}
}

get pollInterval() {
return this._pollInterval
}

set pollInterval(value) {
this._pollInterval = value
}

get skip () {
return this._skip
}
Expand Down