@nxtedition/deepstream.io-client-js 23.4.32 → 23.4.34
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 -25
- 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,56 +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(
|
|
60
|
-
rec.pending === false && rec.refs === 0,
|
|
61
|
-
'cannot prune pending or referenced record'
|
|
62
|
-
)
|
|
59
|
+
invariant(!rec.pending && !rec.ref, 'cannot prune pending or referenced record')
|
|
63
60
|
rec._unsubscribe()
|
|
64
61
|
this._records.delete(rec.name)
|
|
65
62
|
this._stats.destroyed++
|
|
66
63
|
}
|
|
67
64
|
|
|
68
|
-
if (this.
|
|
69
|
-
this.
|
|
65
|
+
if (this._pruningTimeout && this._pruningTimeout.refresh) {
|
|
66
|
+
this._pruningTimeout.refresh()
|
|
70
67
|
} else {
|
|
71
|
-
this.
|
|
72
|
-
if (this.
|
|
73
|
-
this.
|
|
68
|
+
this._pruningTimeout = setTimeout(_prune, 1e3)
|
|
69
|
+
if (this._pruningTimeout.unref) {
|
|
70
|
+
this._pruningTimeout.unref()
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
_prune()
|
|
79
76
|
|
|
80
77
|
this._syncAll = this._syncAll.bind(this)
|
|
81
78
|
}
|
|
82
79
|
|
|
83
80
|
_onRef(rec) {
|
|
84
81
|
if (rec.refs === 0 && !rec.pending) {
|
|
85
|
-
this.
|
|
82
|
+
this._pruning.add(rec)
|
|
86
83
|
} else if (rec.refs === 1) {
|
|
87
|
-
this.
|
|
84
|
+
this._pruning.delete(rec)
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
87
|
|
|
91
88
|
_onPending(rec) {
|
|
92
89
|
if (!rec.pending) {
|
|
93
|
-
this.
|
|
90
|
+
this._pending.delete(rec)
|
|
94
91
|
if (rec.refs === 0) {
|
|
95
|
-
this.
|
|
92
|
+
this._pruning.add(rec)
|
|
96
93
|
}
|
|
97
94
|
} else {
|
|
98
|
-
this.
|
|
95
|
+
this._pending.add(rec)
|
|
99
96
|
if (rec.refs === 0) {
|
|
100
|
-
this.
|
|
97
|
+
this._pruning.delete(rec)
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
}
|
|
@@ -111,8 +108,8 @@ class RecordHandler {
|
|
|
111
108
|
...this._stats,
|
|
112
109
|
listeners: this._listeners.size,
|
|
113
110
|
records: this._records.size,
|
|
114
|
-
pruning: this.
|
|
115
|
-
pending: this.
|
|
111
|
+
pruning: this._pruning.size,
|
|
112
|
+
pending: this._pending.size,
|
|
116
113
|
}
|
|
117
114
|
}
|
|
118
115
|
|
|
@@ -180,7 +177,7 @@ class RecordHandler {
|
|
|
180
177
|
let token
|
|
181
178
|
let timeoutHandle
|
|
182
179
|
|
|
183
|
-
const records = [...this.
|
|
180
|
+
const records = [...this._pending]
|
|
184
181
|
|
|
185
182
|
const onDone = (val) => {
|
|
186
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
|
}
|