Skip to content

Commit 51590c8

Browse files
joelmandellAkryum
authored andcommitted
feat: Reactive pollInterval. (#613) closes #453
* Enhancement Akryum#453 Reactive pollInterval. * Small change for pollInterval enhancement #453 * Remove unnecessary if-check in pollIntervalChanged
1 parent 54ed625 commit 51590c8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/smart-apollo.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class SmartApollo {
1010
this.initialOptions = options
1111
this.options = Object.assign({}, options)
1212
this._skip = false
13+
this._pollInterval = null
1314
this._watchers = []
1415
this._destroyed = false
1516

@@ -29,6 +30,22 @@ export default class SmartApollo {
2930
} else {
3031
this._skip = true
3132
}
33+
34+
if(typeof this.options.pollInterval === 'function') {
35+
this._pollWatcher = this.vm.$watch(this.options.pollInterval.bind(this.vm),this.pollIntervalChanged.bind(this), {immediate:true})
36+
}
37+
}
38+
39+
pollIntervalChanged (value, oldValue) {
40+
if (value !== oldValue) {
41+
this.pollInterval = value
42+
43+
if(value == null) {
44+
this.stopPolling()
45+
} else {
46+
this.startPolling(value)
47+
}
48+
}
3249
}
3350

3451
skipChanged (value, oldValue) {
@@ -37,6 +54,14 @@ export default class SmartApollo {
3754
}
3855
}
3956

57+
get pollInterval() {
58+
return this._pollInterval
59+
}
60+
61+
set pollInterval(value) {
62+
this._pollInterval = value
63+
}
64+
4065
get skip () {
4166
return this._skip
4267
}

0 commit comments

Comments
 (0)