From 87cf9a3582b11ba115a9d19dd3aaa1a7eba61869 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 4 Apr 2017 00:24:58 +0200 Subject: [PATCH] ApolloProvider: New `waitForLoaded` option --- src/apollo-provider.js | 6 +++++- src/dollar-apollo.js | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/apollo-provider.js b/src/apollo-provider.js index d35adbf..b06d0d5 100644 --- a/src/apollo-provider.js +++ b/src/apollo-provider.js @@ -8,8 +8,12 @@ export class ApolloProvider { this._collecting = false } - collect () { + collect (options) { + const finalOptions = Object.assign({}, { + waitForLoaded: true, + }, options) this._promises = [] + this._collectingOptions = finalOptions this._isCollecting = true return () => this._ensureReady() } diff --git a/src/dollar-apollo.js b/src/dollar-apollo.js index f82190a..6816059 100644 --- a/src/dollar-apollo.js +++ b/src/dollar-apollo.js @@ -21,7 +21,9 @@ export class DollarApollo { this.provider._waitFor(new Promise((resolve, reject) => { sub = query.subscribe({ next: result => { - resolve(result) + if (!this.provider._collectingOptions.waitForLoaded || !result.loading) { + resolve(result) + } }, error: error => { reject(error)