teamplay 0.3.15 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/orm/Doc.js +9 -12
- package/package.json +8 -8
- package/utils/MockFinalizationRegistry.js +9 -9
package/orm/Doc.js
CHANGED
|
@@ -162,24 +162,22 @@ class DocSubscriptions {
|
|
|
162
162
|
constructor () {
|
|
163
163
|
this.subCount = new Map()
|
|
164
164
|
this.docs = new Map()
|
|
165
|
-
this.initialized = new Map()
|
|
166
165
|
this.fr = new FinalizationRegistry(segments => this.destroy(segments))
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
init ($doc) {
|
|
170
169
|
const segments = [...$doc[SEGMENTS]]
|
|
171
170
|
const hash = hashDoc(segments)
|
|
172
|
-
if (this.initialized.has(hash)) return
|
|
173
|
-
this.initialized.set(hash, true)
|
|
174
|
-
|
|
175
|
-
this.fr.register($doc, segments, $doc)
|
|
176
|
-
|
|
177
171
|
let doc = this.docs.get(hash)
|
|
178
|
-
if (
|
|
172
|
+
if (doc) {
|
|
173
|
+
if (doc.initialized) return
|
|
174
|
+
doc.init()
|
|
175
|
+
} else {
|
|
179
176
|
doc = new Doc(...segments)
|
|
180
177
|
this.docs.set(hash, doc)
|
|
178
|
+
this.fr.register($doc, segments, $doc)
|
|
179
|
+
doc.init()
|
|
181
180
|
}
|
|
182
|
-
doc.init()
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
subscribe ($doc) {
|
|
@@ -216,11 +214,10 @@ class DocSubscriptions {
|
|
|
216
214
|
const hash = hashDoc(segments)
|
|
217
215
|
const doc = this.docs.get(hash)
|
|
218
216
|
if (!doc) return
|
|
219
|
-
|
|
220
|
-
this.initialized.delete(hash)
|
|
221
|
-
// If the document was initialized as part of query and wasn't directly subscribed to, we should not unsubscribe from it.
|
|
217
|
+
// Wait until after unsubscribe to delete subCount and docs
|
|
222
218
|
if (doc.subscribed) await doc.unsubscribe()
|
|
223
|
-
if (doc.subscribed) return //
|
|
219
|
+
if (doc.subscribed) return // Subscribed again while unsubscribing
|
|
220
|
+
this.subCount.delete(hash)
|
|
224
221
|
this.docs.delete(hash)
|
|
225
222
|
}
|
|
226
223
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@nx-js/observer-util": "^4.1.3",
|
|
26
|
-
"@teamplay/backend": "^0.3.
|
|
27
|
-
"@teamplay/cache": "^0.3.
|
|
28
|
-
"@teamplay/channel": "^0.3.
|
|
29
|
-
"@teamplay/debug": "^0.3.
|
|
30
|
-
"@teamplay/schema": "^0.3.
|
|
31
|
-
"@teamplay/utils": "^0.3.
|
|
26
|
+
"@teamplay/backend": "^0.3.16",
|
|
27
|
+
"@teamplay/cache": "^0.3.16",
|
|
28
|
+
"@teamplay/channel": "^0.3.16",
|
|
29
|
+
"@teamplay/debug": "^0.3.16",
|
|
30
|
+
"@teamplay/schema": "^0.3.16",
|
|
31
|
+
"@teamplay/utils": "^0.3.16",
|
|
32
32
|
"diff-match-patch": "^1.0.5",
|
|
33
33
|
"events": "^3.3.0",
|
|
34
34
|
"json0-ot-diff": "^1.1.2",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
]
|
|
64
64
|
},
|
|
65
65
|
"license": "MIT",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "92ca8b74d176193e90f8a379eeaec31299b807bb"
|
|
67
67
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export const REGISTRY_SWEEP_INTERVAL =
|
|
2
|
-
export const MOCK_FINALIZATION_TIMEOUT = 10_000
|
|
3
|
-
const PERMANENT = false
|
|
1
|
+
export const REGISTRY_SWEEP_INTERVAL = 10000
|
|
4
2
|
|
|
5
3
|
// This is a mock implementation of FinalizationRegistry which doesn't actually
|
|
6
4
|
// finalize anything. It's used in environments where FinalizationRegistry is not
|
|
@@ -42,7 +40,7 @@ export class WeakRefBasedFinalizationRegistry {
|
|
|
42
40
|
register (target, value, token) {
|
|
43
41
|
this.registrations.set(this.counter, {
|
|
44
42
|
targetRef: new WeakRef(target),
|
|
45
|
-
tokenRef: token
|
|
43
|
+
tokenRef: token != null ? new WeakRef(token) : undefined,
|
|
46
44
|
value
|
|
47
45
|
})
|
|
48
46
|
this.counter++
|
|
@@ -50,9 +48,11 @@ export class WeakRefBasedFinalizationRegistry {
|
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
unregister (token) {
|
|
51
|
+
if (token == null) return
|
|
53
52
|
this.registrations.forEach((registration, key) => {
|
|
54
|
-
if (registration?.
|
|
55
|
-
|
|
53
|
+
if (registration.tokenRef?.deref() === token) {
|
|
54
|
+
this.registrations.delete(key)
|
|
55
|
+
}
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -65,7 +65,7 @@ export class WeakRefBasedFinalizationRegistry {
|
|
|
65
65
|
if (registration.targetRef.deref() !== undefined) return
|
|
66
66
|
const value = registration.value
|
|
67
67
|
this.registrations.delete(key)
|
|
68
|
-
|
|
68
|
+
this.finalize(value)
|
|
69
69
|
})
|
|
70
70
|
|
|
71
71
|
if (this.registrations.size > 0) this.scheduleSweep()
|
|
@@ -81,12 +81,12 @@ let ExportedFinalizationRegistry
|
|
|
81
81
|
|
|
82
82
|
if (typeof FinalizationRegistry !== 'undefined') {
|
|
83
83
|
ExportedFinalizationRegistry = FinalizationRegistry
|
|
84
|
-
} else if (typeof WeakRef !== 'undefined'
|
|
84
|
+
} else if (typeof WeakRef !== 'undefined') {
|
|
85
85
|
console.warn('FinalizationRegistry is not available in this environment. ' +
|
|
86
86
|
'Using a mock implementation: WeakRefBasedFinalizationRegistry')
|
|
87
87
|
ExportedFinalizationRegistry = WeakRefBasedFinalizationRegistry
|
|
88
88
|
} else {
|
|
89
|
-
console.warn('FinalizationRegistry
|
|
89
|
+
console.warn('Neither FinalizationRegistry nor WeakRef are available in this environment. ' +
|
|
90
90
|
'Using a mock implementation: PermanentFinalizationRegistry')
|
|
91
91
|
ExportedFinalizationRegistry = PermanentFinalizationRegistry
|
|
92
92
|
}
|