Skip to content

Commit

Permalink
fix: should properly stop and restart subcribe to more subs after que…
Browse files Browse the repository at this point in the history
…ry is restarted, closes #677
  • Loading branch information
Guillaume Chau committed Sep 30, 2019
1 parent 970dc2b commit 9546360
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dollar-apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ export class DollarApollo {
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
smart.autostart()

if (options.linkedQuery) {
options.linkedQuery._linkedSubscriptions.push(smart)
}

return smart
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/smart-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class SmartQuery extends SmartApollo {
type = 'query'
vueApolloSpecialKeys = VUE_APOLLO_QUERY_KEYWORDS
_loading = false
_linkedSubscriptions = []

constructor (vm, key, options, autostart = true) {
// Add reactive data related to the query
Expand Down Expand Up @@ -86,6 +87,11 @@ export default class SmartQuery extends SmartApollo {
return
}
this.sub.unsubscribe()

// Subscribe to more subs
for (const sub of this._linkedSubscriptions) {
sub.stop()
}
}

this.previousVariablesJson = variablesJson
Expand All @@ -104,6 +110,11 @@ export default class SmartQuery extends SmartApollo {
}

super.executeApollo(variables)

// Subscribe to more subs
for (const sub of this._linkedSubscriptions) {
sub.start()
}
}

startQuerySubscription () {
Expand Down

0 comments on commit 9546360

Please sign in to comment.