From 1238c513318714f60da261b80a7c724cfe69b511 Mon Sep 17 00:00:00 2001 From: Ben52 Date: Mon, 19 Feb 2018 21:54:28 -0500 Subject: [PATCH 1/2] Pass back `isLoading` to scoped-slot Right now `loading` is only set when a result is received, not when the request is sent. Using `watchLoading`, we can pass the loading state from when the request is sent. --- src/components/ApolloQuery.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/ApolloQuery.js b/src/components/ApolloQuery.js index 2e43fbf5..c2edacaa 100644 --- a/src/components/ApolloQuery.js +++ b/src/components/ApolloQuery.js @@ -67,6 +67,7 @@ export default { networkStatus: 7, error: null, }, + isLoading: false, } }, @@ -105,6 +106,9 @@ export default { context () { return this.context }, skip () { return this.skip }, manual: true, + watchLoading(isLoading) { + this.isLoading = isLoading + }, result (result) { const { errors, loading, networkStatus } = result let { error } = result @@ -156,6 +160,7 @@ export default { let result = this.$scopedSlots.default({ result: this.result, query: this.$apollo.queries.query, + isLoading: this.isLoading, }) if (Array.isArray(result)) { result = result.concat(this.$slots.default) From 05cf6ad6c053180fec283a5af7091984aa8e02b7 Mon Sep 17 00:00:00 2001 From: Ben52 Date: Mon, 19 Feb 2018 22:13:21 -0500 Subject: [PATCH 2/2] Use $apolloData.loading We can simply use the $apolloData.loading property to get the current loading state of the query. --- src/components/ApolloQuery.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/ApolloQuery.js b/src/components/ApolloQuery.js index c2edacaa..af6a34df 100644 --- a/src/components/ApolloQuery.js +++ b/src/components/ApolloQuery.js @@ -67,7 +67,6 @@ export default { networkStatus: 7, error: null, }, - isLoading: false, } }, @@ -106,9 +105,6 @@ export default { context () { return this.context }, skip () { return this.skip }, manual: true, - watchLoading(isLoading) { - this.isLoading = isLoading - }, result (result) { const { errors, loading, networkStatus } = result let { error } = result @@ -160,7 +156,7 @@ export default { let result = this.$scopedSlots.default({ result: this.result, query: this.$apollo.queries.query, - isLoading: this.isLoading, + isLoading: this.$apolloData.loading, }) if (Array.isArray(result)) { result = result.concat(this.$slots.default)