fix: compare serialized variables to prevent unnecessary fetch

This commit is contained in:
Guillaume Chau
2020-01-22 13:28:41 +01:00
parent 32d1f7568e
commit 3a473e2643
2 changed files with 16 additions and 6 deletions
@@ -323,9 +323,14 @@ export function useQuery<
// Applying variables
let currentVariables: TVariables
watch(variablesRef, value => {
currentVariables = value
restart()
let currentVariablesSerialized: string
watch(variablesRef, (value, oldValue) => {
const serialized = JSON.stringify(value)
if (serialized !== currentVariablesSerialized) {
currentVariables = value
restart()
}
currentVariablesSerialized = serialized
}, {
deep: true,
})
@@ -211,9 +211,14 @@ export function useSubscription <
// Applying variables
let currentVariables: TVariables
watch(variablesRef, value => {
currentVariables = value
restart()
let currentVariablesSerialized: string
watch(variablesRef, (value, oldValue) => {
const serialized = JSON.stringify(value)
if (serialized !== currentVariablesSerialized) {
currentVariables = value
restart()
}
currentVariablesSerialized = serialized
}, {
deep: true,
})