Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 14, 2024
1 parent e772799 commit f29aa6c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/vanilla/utils/proxyMap.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -21,10 +16,17 @@ export function proxyMap<K, V>(entries?: Iterable<[K, V]> | undefined | null) {
const indexMap = new Map<K, number>()
const snapMapCache = new WeakMap<object, Map<K, number>>()
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
Expand Down Expand Up @@ -57,16 +59,15 @@ export function proxyMap<K, V>(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
Expand Down

0 comments on commit f29aa6c

Please sign in to comment.