@nxtedition/deepstream.io-client-js 23.4.33 → 23.4.35
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/package.json +1 -1
- package/src/record/record-handler.js +22 -22
- package/src/record/record.js +13 -4
package/package.json
CHANGED
|
@@ -24,8 +24,8 @@ class RecordHandler {
|
|
|
24
24
|
this._client = client
|
|
25
25
|
this._records = new Map()
|
|
26
26
|
this._listeners = new Map()
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
27
|
+
this._pending = new Set()
|
|
28
|
+
this._pruning = new Set()
|
|
29
29
|
|
|
30
30
|
this._connected = 0
|
|
31
31
|
this._stats = {
|
|
@@ -48,53 +48,53 @@ class RecordHandler {
|
|
|
48
48
|
|
|
49
49
|
this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
|
|
50
50
|
|
|
51
|
-
this.
|
|
51
|
+
this._pruningTimeout = null
|
|
52
52
|
|
|
53
53
|
// TODO (perf): schedule & yield to avoid blocking event loop?
|
|
54
|
-
const
|
|
55
|
-
const prune = this.
|
|
54
|
+
const _prune = () => {
|
|
55
|
+
const prune = this._pruning
|
|
56
56
|
|
|
57
|
-
this.
|
|
57
|
+
this._pruning = new Set()
|
|
58
58
|
for (const rec of prune) {
|
|
59
|
-
invariant(!rec.pending && !rec.
|
|
59
|
+
invariant(!rec.pending && !rec.refs, 'cannot prune pending or referenced record')
|
|
60
60
|
rec._unsubscribe()
|
|
61
61
|
this._records.delete(rec.name)
|
|
62
62
|
this._stats.destroyed++
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
if (this.
|
|
66
|
-
this.
|
|
65
|
+
if (this._pruningTimeout && this._pruningTimeout.refresh) {
|
|
66
|
+
this._pruningTimeout.refresh()
|
|
67
67
|
} else {
|
|
68
|
-
this.
|
|
69
|
-
if (this.
|
|
70
|
-
this.
|
|
68
|
+
this._pruningTimeout = setTimeout(_prune, 1e3)
|
|
69
|
+
if (this._pruningTimeout.unref) {
|
|
70
|
+
this._pruningTimeout.unref()
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
_prune()
|
|
76
76
|
|
|
77
77
|
this._syncAll = this._syncAll.bind(this)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
_onRef(rec) {
|
|
81
81
|
if (rec.refs === 0 && !rec.pending) {
|
|
82
|
-
this.
|
|
82
|
+
this._pruning.add(rec)
|
|
83
83
|
} else if (rec.refs === 1) {
|
|
84
|
-
this.
|
|
84
|
+
this._pruning.delete(rec)
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
_onPending(rec) {
|
|
89
89
|
if (!rec.pending) {
|
|
90
|
-
this.
|
|
90
|
+
this._pending.delete(rec)
|
|
91
91
|
if (rec.refs === 0) {
|
|
92
|
-
this.
|
|
92
|
+
this._pruning.add(rec)
|
|
93
93
|
}
|
|
94
94
|
} else {
|
|
95
|
-
this.
|
|
95
|
+
this._pending.add(rec)
|
|
96
96
|
if (rec.refs === 0) {
|
|
97
|
-
this.
|
|
97
|
+
this._pruning.delete(rec)
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -108,8 +108,8 @@ class RecordHandler {
|
|
|
108
108
|
...this._stats,
|
|
109
109
|
listeners: this._listeners.size,
|
|
110
110
|
records: this._records.size,
|
|
111
|
-
pruning: this.
|
|
112
|
-
pending: this.
|
|
111
|
+
pruning: this._pruning.size,
|
|
112
|
+
pending: this._pending.size,
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -177,7 +177,7 @@ class RecordHandler {
|
|
|
177
177
|
let token
|
|
178
178
|
let timeoutHandle
|
|
179
179
|
|
|
180
|
-
const records = [...this.
|
|
180
|
+
const records = [...this._pending]
|
|
181
181
|
|
|
182
182
|
const onDone = (val) => {
|
|
183
183
|
if (done) {
|
package/src/record/record.js
CHANGED
|
@@ -21,7 +21,7 @@ class Record {
|
|
|
21
21
|
this._subscriptions = []
|
|
22
22
|
this._updating = null
|
|
23
23
|
this._patches = null
|
|
24
|
-
this.
|
|
24
|
+
this._pending = false
|
|
25
25
|
|
|
26
26
|
this._subscribe()
|
|
27
27
|
}
|
|
@@ -47,7 +47,7 @@ class Record {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
get pending() {
|
|
50
|
-
return this.
|
|
50
|
+
return this._pending
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
ref() {
|
|
@@ -243,7 +243,7 @@ class Record {
|
|
|
243
243
|
|
|
244
244
|
_unsubscribe() {
|
|
245
245
|
invariant(!this._refs, this._name + ' must not have refs')
|
|
246
|
-
invariant(!this.
|
|
246
|
+
invariant(!this._patches, this._name + ' must not have patches')
|
|
247
247
|
|
|
248
248
|
const prevState = this._state
|
|
249
249
|
|
|
@@ -263,6 +263,11 @@ class Record {
|
|
|
263
263
|
_subscribe() {
|
|
264
264
|
invariant(this._refs, this._name + ' missing refs')
|
|
265
265
|
|
|
266
|
+
if (!this._pending) {
|
|
267
|
+
this._pending = true
|
|
268
|
+
this._handler._onPending(this)
|
|
269
|
+
}
|
|
270
|
+
|
|
266
271
|
const connection = this._handler._connection
|
|
267
272
|
if (!this._subscribed && connection.connected) {
|
|
268
273
|
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
@@ -318,12 +323,16 @@ class Record {
|
|
|
318
323
|
}
|
|
319
324
|
|
|
320
325
|
this._patches = null
|
|
321
|
-
this._handler._onPending(this)
|
|
322
326
|
} else if (version.charAt(0) === 'I' || utils.compareRev(version, this._version) > 0) {
|
|
323
327
|
this._version = version
|
|
324
328
|
this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
|
|
325
329
|
}
|
|
326
330
|
|
|
331
|
+
if (this._pending) {
|
|
332
|
+
this._pending = false
|
|
333
|
+
this._handler._onPending(this)
|
|
334
|
+
}
|
|
335
|
+
|
|
327
336
|
if (this._state < Record.STATE.SERVER) {
|
|
328
337
|
this._state = this._version.charAt(0) === 'I' ? Record.STATE.STALE : Record.STATE.SERVER
|
|
329
338
|
}
|