33import type { ResultType , Schema } from '@rocicorp/zero'
44import type { Change , Entry , Format , HumanReadable , Input , Output , Query , ViewFactory } from '@rocicorp/zero/advanced'
55import { applyChange } from '@rocicorp/zero/advanced'
6- import { reactive } from 'vue'
6+ import { reactive , toRaw } from 'vue'
77
88interface QueryResultDetails {
99 readonly type : ResultType
@@ -14,11 +14,33 @@ type State = [Entry, QueryResultDetails]
1414const complete = { type : 'complete' } as const
1515const 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+
1739class 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