teamplay 0.4.0-alpha.39 → 0.4.0-alpha.40
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 +40 -15
- package/package.json +2 -2
package/orm/Doc.js
CHANGED
|
@@ -40,10 +40,6 @@ class Doc {
|
|
|
40
40
|
|
|
41
41
|
async unsubscribe () {
|
|
42
42
|
await this.lifecycle.unsubscribe()
|
|
43
|
-
if (!this.subscribed) {
|
|
44
|
-
this.initialized = undefined
|
|
45
|
-
this._removeData()
|
|
46
|
-
}
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
async _subscribe () {
|
|
@@ -60,21 +56,40 @@ class Doc {
|
|
|
60
56
|
async _unsubscribe () {
|
|
61
57
|
const doc = getConnection().get(this.collection, this.docId)
|
|
62
58
|
await new Promise((resolve, reject) => {
|
|
63
|
-
// First unsubscribe cleanly, then destroy to remove from connection.collections.
|
|
64
|
-
// We can't call destroy() directly because it has a race condition: if connection.get()
|
|
65
|
-
// is called before destroy completes (e.g. rapid unsub/resub), it resets _wantsDestroy
|
|
66
|
-
// creating a corrupted state ("Cannot read properties of null (reading 'callback')").
|
|
67
|
-
// By unsubscribing first and destroying in the callback, the doc is in a clean state.
|
|
68
59
|
doc.unsubscribe(err => {
|
|
69
60
|
if (err) return reject(err)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
resolve()
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
hasPending () {
|
|
67
|
+
const doc = getConnection().get(this.collection, this.docId)
|
|
68
|
+
if (typeof doc.hasPending !== 'function') return false
|
|
69
|
+
return doc.hasPending()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
whenNothingPending (fn) {
|
|
73
|
+
const doc = getConnection().get(this.collection, this.docId)
|
|
74
|
+
if (typeof doc.whenNothingPending !== 'function') return fn()
|
|
75
|
+
doc.whenNothingPending(fn)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async destroy () {
|
|
79
|
+
const doc = getConnection().get(this.collection, this.docId)
|
|
80
|
+
await new Promise((resolve, reject) => {
|
|
81
|
+
doc.destroy(err => {
|
|
82
|
+
if (err) return reject(err)
|
|
83
|
+
resolve()
|
|
74
84
|
})
|
|
75
85
|
})
|
|
76
86
|
}
|
|
77
87
|
|
|
88
|
+
dispose () {
|
|
89
|
+
this.initialized = undefined
|
|
90
|
+
this._removeData()
|
|
91
|
+
}
|
|
92
|
+
|
|
78
93
|
_initData () {
|
|
79
94
|
const doc = getConnection().get(this.collection, this.docId)
|
|
80
95
|
this._refData()
|
|
@@ -259,13 +274,23 @@ export class DocSubscriptions {
|
|
|
259
274
|
this.subCount.delete(hash)
|
|
260
275
|
return
|
|
261
276
|
}
|
|
262
|
-
this.subCount.delete(hash)
|
|
263
277
|
// Always call unsubscribe() - if doc is in SUBSCRIBING state, the state machine
|
|
264
278
|
// will queue a pending unsubscribe to execute after subscribe completes
|
|
265
279
|
await doc.unsubscribe()
|
|
266
280
|
if (doc.subscribed) return // Subscribed again while unsubscribing
|
|
267
|
-
if ((this.subCount.get(hash) || 0) > 0) return
|
|
281
|
+
if (!options.force && (this.subCount.get(hash) || 0) > 0) return
|
|
282
|
+
if (typeof doc.hasPending === 'function' && doc.hasPending()) {
|
|
283
|
+
if (typeof doc.whenNothingPending === 'function') {
|
|
284
|
+
doc.whenNothingPending(() => {
|
|
285
|
+
this.destroyByHash(hash, options).catch(ignoreDestroyError)
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
if (typeof doc.destroy === 'function') await doc.destroy()
|
|
291
|
+
if (typeof doc.dispose === 'function') doc.dispose()
|
|
268
292
|
this.docs.delete(hash)
|
|
293
|
+
this.subCount.delete(hash)
|
|
269
294
|
}
|
|
270
295
|
}
|
|
271
296
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.40",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
]
|
|
83
83
|
},
|
|
84
84
|
"license": "MIT",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "24677e6b7b4da7c899fbf772a440719281227915"
|
|
86
86
|
}
|