Skip to content

Commit

Permalink
fix(useMemoize): use shallowReactive to wrap Map
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 4, 2023
1 parent c51d140 commit fecbe00
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/core/useMemoize/index.ts
@@ -1,5 +1,5 @@
import { hasOwn } from '@vueuse/shared'
import { del, isVue2, reactive, set } from 'vue-demi'
import { del, isVue2, set, shallowReactive } from 'vue-demi'

type CacheKey = any

Expand Down Expand Up @@ -33,7 +33,7 @@ export interface UseMemoizeCache<Key, Value> {
* Fallback for Vue 2 not able to make a reactive Map
*/
function getMapVue2Compat<Value>(): UseMemoizeCache<CacheKey, Value> {
const data: Record<CacheKey, Value> = reactive({})
const data: Record<CacheKey, Value> = shallowReactive({})
return {
get: key => data[key],
set: (key, value) => set(data, key, value),
Expand Down Expand Up @@ -91,11 +91,11 @@ export function useMemoize<Result, Args extends unknown[]>(
): UseMemoizeReturn<Result, Args> {
const initCache = (): UseMemoizeCache<CacheKey, Result> => {
if (options?.cache)
return reactive(options.cache)
return shallowReactive(options.cache)
// Use fallback for Vue 2 not able to make a reactive Map
if (isVue2)
return getMapVue2Compat<Result>()
return reactive(new Map<CacheKey, Result>())
return shallowReactive(new Map<CacheKey, Result>())
}
const cache = initCache()

Expand Down

0 comments on commit fecbe00

Please sign in to comment.