diff --git a/src/vanilla/utils/proxyMap.ts b/src/vanilla/utils/proxyMap.ts index d591881d..14f67f5e 100644 --- a/src/vanilla/utils/proxyMap.ts +++ b/src/vanilla/utils/proxyMap.ts @@ -1,9 +1,4 @@ -import { - proxy, - snapshot, - subscribe, - unstable_getInternalStates, -} from '../../vanilla.ts' +import { proxy, unstable_getInternalStates } from '../../vanilla.ts' const { proxyStateMap, snapCache } = unstable_getInternalStates() const maybeProxify = (x: any) => (typeof x === 'object' ? proxy({ x }).x : x) @@ -21,10 +16,17 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { const indexMap = new Map() const snapMapCache = new WeakMap>() const registerSnapMap = () => { - const cache = snapCache.get(indexMap) + const cache = snapCache.get(vObject) const latestSnap = cache?.[1] if (latestSnap && !snapMapCache.has(latestSnap)) { - snapMapCache.set(latestSnap, indexMap) + const clonedMap = new Map(indexMap) + // TODO: should we support snapshot keys? + // for (const [k, i] of indexMap) { + // if (isProxy(k)) { + // clonedMap.set(snapshot(k as object) as K, i) + // } + // } + snapMapCache.set(latestSnap, clonedMap) return true } return false @@ -57,16 +59,15 @@ export function proxyMap(entries?: Iterable<[K, V]> | undefined | null) { get(key: K) { const map = getSnapMap(this) || indexMap const k = maybeProxify(key) - if (!map.has(k)) { + const index = map.get(k) + if (index === undefined) { if (!isProxy(this)) { // eslint-disable-next-line @typescript-eslint/no-unused-expressions this.index } return undefined } - - const index = map.get(k) - return index ? (this.data[index + 1] as V) : undefined + return this.data[index + 1] as V }, has(key: K) { const map = getSnapMap(this) || indexMap