Skip to content

Commit

Permalink
Merge pull request #332 from PrefectHQ/duplicates
Browse files Browse the repository at this point in the history
Fix: Add a check for isEqual to reduce duplicate queries
  • Loading branch information
zhen0 authored Oct 26, 2023
2 parents 345e8c2 + 9408db0 commit 3aac7c0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/useRouteQueryParam/useRouteQueryParam.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/unified-signatures */
import { computed, Ref } from 'vue'
import isEqual from 'lodash.isequal'
import { ref, Ref, watch } from 'vue'
import { NoInfer } from '@/types/generics'
import { MaybeArray } from '@/types/maybe'
import { useRouteQuery } from '@/useRouteQuery/useRouteQuery'
Expand Down Expand Up @@ -43,12 +44,21 @@ export function useRouteQueryParam(key: string, formatterOrDefaultValue?: RouteP
const defaultValue = maybeDefaultValue
const format = new formatter({ key, defaultValue, multiple })

return computed({
get() {
return format.get(query)
},
set(value) {
format.set(query, value)
},
const param = ref(format.get(query))

watch(() => query, query => {
const newValue = format.get(query)

if (isEqual(newValue, param)) {
return
}

param.value = newValue
})

watch(param, param => {
format.set(query, param)
})

return param
}

0 comments on commit 3aac7c0

Please sign in to comment.