Skip to content

Commit

Permalink
fix: use onBeforeUnmount
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Dec 17, 2019
1 parent 2a9ca9f commit 9c4b6b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/vue-apollo-composable/src/useMutation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentNode } from 'graphql'
import { MutationOptions, OperationVariables } from 'apollo-client'
import { ref } from '@vue/composition-api'
import { ref, onBeforeUnmount } from '@vue/composition-api'
import { FetchResult } from 'apollo-link'
import { useApolloClient } from './useApolloClient'
import { ReactiveFunction } from './util/ReactiveFunction'
Expand Down Expand Up @@ -73,6 +73,10 @@ export function useMutation<
}
}

onBeforeUnmount(() => {
loading.value = false
})

return {
mutate,
loading,
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref, Ref, isRef, computed, watch, onServerPrefetch, onUnmounted, getCurrentInstance } from '@vue/composition-api'
import { ref, Ref, isRef, computed, watch, onServerPrefetch, getCurrentInstance, onBeforeUnmount } from '@vue/composition-api'
import Vue from 'vue'
import { DocumentNode } from 'graphql'
import {
Expand Down Expand Up @@ -373,7 +373,7 @@ export function useQuery<
})

// Teardown
onUnmounted(() => {
onBeforeUnmount(() => {
stop()
subscribeToMoreItems.length = 0
})
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-apollo-composable/src/useSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentNode } from 'graphql'
import Vue from 'vue'
import { Ref, ref, watch, isRef, onUnmounted, computed, getCurrentInstance } from '@vue/composition-api'
import { Ref, ref, watch, isRef, computed, getCurrentInstance, onBeforeUnmount } from '@vue/composition-api'
import { OperationVariables, SubscriptionOptions } from 'apollo-client'
import { Observable, Subscription } from 'apollo-client/util/Observable'
import { FetchResult } from 'apollo-link'
Expand Down Expand Up @@ -188,7 +188,7 @@ export function useSubscription <
})

// Teardown
onUnmounted(stop)
onBeforeUnmount(stop)

return {
result,
Expand Down

0 comments on commit 9c4b6b0

Please sign in to comment.