Skip to content

Commit 0808a65

Browse files
committed
fix: unwrap vue proxies in refCountMap
#42 (comment)
1 parent 3c9d4e6 commit 0808a65

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/view.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import type { ResultType, Schema } from '@rocicorp/zero'
44
import type { Change, Entry, Format, HumanReadable, Input, Output, Query, ViewFactory } from '@rocicorp/zero/advanced'
55
import { applyChange } from '@rocicorp/zero/advanced'
6-
import { reactive } from 'vue'
6+
import { reactive, toRaw } from 'vue'
77

88
interface QueryResultDetails {
99
readonly type: ResultType
@@ -14,11 +14,33 @@ type State = [Entry, QueryResultDetails]
1414
const complete = { type: 'complete' } as const
1515
const unknown = { type: 'unknown' } as const
1616

17+
interface RefCountMap {
18+
get: (entry: Entry) => number | undefined
19+
set: (entry: Entry, refCount: number) => void
20+
delete: (entry: Entry) => boolean
21+
}
22+
23+
class VueRefCountMap implements RefCountMap {
24+
readonly #map = new WeakMap<Entry, number>()
25+
26+
get(entry: Entry) {
27+
return this.#map.get(toRaw(entry))
28+
}
29+
30+
set(entry: Entry, refCount: number) {
31+
this.#map.set(toRaw(entry), refCount)
32+
}
33+
34+
delete(entry: Entry) {
35+
return this.#map.delete(toRaw(entry))
36+
}
37+
}
38+
1739
class VueView<V> implements Output {
1840
readonly #input: Input
1941
readonly #format: Format
2042
readonly #onDestroy: () => void
21-
readonly #refCountMap = new WeakMap<Entry, number>()
43+
readonly #refCountMap = new VueRefCountMap()
2244

2345
#state: State
2446

0 commit comments

Comments
 (0)