fix: use onBeforeUnmount

This commit is contained in:
Guillaume Chau 2019-12-17 11:07:50 +01:00
parent 2a9ca9f7fa
commit 9c4b6b09b7
3 changed files with 9 additions and 5 deletions

View File

@ -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'
@ -73,6 +73,10 @@ export function useMutation<
}
}
onBeforeUnmount(() => {
loading.value = false
})
return {
mutate,
loading,

View File

@ -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 {
@ -373,7 +373,7 @@ export function useQuery<
})
// Teardown
onUnmounted(() => {
onBeforeUnmount(() => {
stop()
subscribeToMoreItems.length = 0
})

View File

@ -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'
@ -188,7 +188,7 @@ export function useSubscription <
})
// Teardown
onUnmounted(stop)
onBeforeUnmount(stop)
return {
result,