From fa450d0ff237feaa48571278ab882a2522aaeb3a Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Mon, 28 Aug 2017 15:59:27 +0200 Subject: [PATCH] Now supports multiple subscribeToMore on query --- README.md | 2 ++ src/dollar-apollo.js | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d3811fb..7815fc2 100644 --- a/README.md +++ b/README.md @@ -743,6 +743,8 @@ apollo: { } ``` +*Note that you can pass an array of subscriptions to `subscribeToMore` to subscribe to multiple subcribtions on this query.* + #### Alternate usage You can access the queries you defined in the `apollo` option with `this.$apollo.queries.`, so it would look like this: diff --git a/src/dollar-apollo.js b/src/dollar-apollo.js index 0ffd244..3a70d7e 100644 --- a/src/dollar-apollo.js +++ b/src/dollar-apollo.js @@ -77,11 +77,21 @@ export class DollarApollo { const smart = this.queries[key] = new SmartQuery(this.vm, key, options, false) smart.autostart() - if (options.subscribeToMore) { - this.addSmartSubscription(key, { - ...options.subscribeToMore, - linkedQuery: smart, - }) + const subs = options.subscribeToMore + if (subs) { + if (Array.isArray(subs)) { + subs.forEach((sub, index) => { + this.addSmartSubscription(`${key}${index}`, { + ...sub, + linkedQuery: smart, + }) + }) + } else { + this.addSmartSubscription(key, { + ...subs, + linkedQuery: smart, + }) + } } return smart