Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Oct 16, 2024
1 parent 7e0b6e8 commit 6ee95c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
10 changes: 5 additions & 5 deletions src/vanilla/utils/proxyMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function proxyMap<K, V>(entries?: Iterable<[K, V]> | undefined | null) {
const index = map.get(key)
if (index === undefined) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.index
this.index // touch property for tracking
return undefined
}
return this.data[index]
Expand All @@ -62,7 +62,7 @@ export function proxyMap<K, V>(entries?: Iterable<[K, V]> | undefined | null) {
const exists = map.has(key)
if (!exists) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.index
this.index // touch property for tracking
}
return exists
},
Expand All @@ -71,11 +71,11 @@ export function proxyMap<K, V>(entries?: Iterable<[K, V]> | undefined | null) {
throw new Error('Cannot perform mutations on a snapshot')
}
const index = indexMap.get(key)
if (index !== undefined) {
this.data[index] = value
} else {
if (index === undefined) {
indexMap.set(key, this.index)
this.data[this.index++] = value
} else {
this.data[index] = value
}
return this
},
Expand Down
24 changes: 11 additions & 13 deletions src/vanilla/utils/proxySet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function proxySet<T>(initialValues?: Iterable<T> | null) {
if (typeof initialValues[Symbol.iterator] !== 'function') {
throw new TypeError('not iterable')
}
for (const v of initialValues) {
if (!indexMap.has(v)) {
const value = maybeProxify(v)
indexMap.set(value, initialIndex)
initialData[initialIndex++] = value
for (const value of initialValues) {
if (!indexMap.has(value)) {
const v = maybeProxify(value)
indexMap.set(v, initialIndex)
initialData[initialIndex++] = v
}
}
}
Expand All @@ -54,13 +54,13 @@ export function proxySet<T>(initialValues?: Iterable<T> | null) {
}
return indexMap.size
},
has(v: T) {
has(value: T) {
const map = getMapForThis(this)
const value = maybeProxify(v)
const exists = map.has(value)
const v = maybeProxify(value)
const exists = map.has(v)
if (!exists) {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.index
this.index // touch property for tracking
}
return exists
},
Expand All @@ -70,10 +70,8 @@ export function proxySet<T>(initialValues?: Iterable<T> | null) {
}
const v = maybeProxify(value)
if (!indexMap.has(v)) {
let nextIndex = this.index
indexMap.set(v, nextIndex)
this.data[nextIndex++] = v
this.index = nextIndex
indexMap.set(v, this.index)
this.data[this.index++] = v
}
return this
},
Expand Down

0 comments on commit 6ee95c7

Please sign in to comment.