Skip to content

Commit b52122d

Browse files
author
Guillaume Chau
committed
Improved collect/ensureReady
1 parent 4612b06 commit b52122d

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-apollo",
3-
"version": "2.1.0-beta.4",
3+
"version": "2.1.0-beta.5",
44
"description": "Vue apollo integration",
55
"main": "lib/index.js",
66
"scripts": {

src/apollo-provider.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,32 @@ export class ApolloProvider {
33
if (!options) {
44
throw new Error('Options argument required')
55
}
6-
this.clients = options.clients
7-
this.defaultClient = options.defaultClient
6+
this.clients = options.clients || {}
7+
this.clients.defaultClient = this.defaultClient = options.defaultClient
88
this._collecting = false
99
}
1010

1111
collect (options) {
1212
const finalOptions = Object.assign({}, {
1313
waitForLoaded: true,
1414
}, options)
15+
this._ready = false
1516
this._promises = []
1617
this._collectingOptions = finalOptions
1718
this._isCollecting = true
18-
return () => this._ensureReady()
19+
this._ensureReadyPromise = null
20+
return this.ensureReady
21+
}
22+
23+
ensureReady () {
24+
if (this._ready) {
25+
return Promise.resolve()
26+
} else {
27+
if (!this._ensureReadyPromise) {
28+
this._ensureReadyPromise = this._ensureReady()
29+
}
30+
return this._ensureReadyPromise
31+
}
1932
}
2033

2134
_waitFor (promise) {
@@ -26,6 +39,9 @@ export class ApolloProvider {
2639

2740
_ensureReady () {
2841
this._isCollecting = false
29-
return Promise.all(this._promises)
42+
return Promise.all(this._promises).then((result) => {
43+
this._ready = true
44+
return result
45+
})
3046
}
3147
}

src/dollar-apollo.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,12 @@ export class DollarApollo {
9797

9898
option (key, options) {
9999
const smart = this.queries[key] = new SmartQuery(this.vm, key, options, false)
100-
this.vm.$nextTick(() => {
101-
smart.autostart()
102-
})
100+
smart.autostart()
103101
}
104102

105103
subscribeOption (key, options) {
106104
const smart = this.subscriptions[key] = new SmartSubscription(this.vm, key, options, false)
107-
this.vm.$nextTick(() => {
108-
smart.autostart()
109-
})
105+
smart.autostart()
110106
}
111107

112108
defineReactiveSetter (key, func) {

0 commit comments

Comments
 (0)