@nxtedition/deepstream.io-client-js 23.4.41 → 23.4.42
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.js +33 -38
package/package.json
CHANGED
package/src/record/record.js
CHANGED
|
@@ -232,8 +232,6 @@ class Record {
|
|
|
232
232
|
}
|
|
233
233
|
|
|
234
234
|
_$onConnectionStateChange() {
|
|
235
|
-
const prevState = this._state
|
|
236
|
-
|
|
237
235
|
const connection = this._handler._connection
|
|
238
236
|
if (connection.connected) {
|
|
239
237
|
if (this._refs > 0) {
|
|
@@ -247,12 +245,21 @@ class Record {
|
|
|
247
245
|
}
|
|
248
246
|
} else {
|
|
249
247
|
this._subscribed = false
|
|
250
|
-
this._state
|
|
251
|
-
|
|
248
|
+
if (this._state > Record.STATE.CLIENT) {
|
|
249
|
+
this._state = Record.STATE.CLIENT
|
|
250
|
+
this._handler._onPending(this)
|
|
251
|
+
this._emitUpdate()
|
|
252
|
+
}
|
|
252
253
|
}
|
|
254
|
+
}
|
|
253
255
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
+
_subscribe() {
|
|
257
|
+
invariant(this._refs, this._name + ' missing refs')
|
|
258
|
+
|
|
259
|
+
const connection = this._handler._connection
|
|
260
|
+
if (!this._subscribed && connection.connected) {
|
|
261
|
+
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
262
|
+
this._subscribed = true
|
|
256
263
|
}
|
|
257
264
|
}
|
|
258
265
|
|
|
@@ -260,31 +267,19 @@ class Record {
|
|
|
260
267
|
invariant(!this._refs, this._name + ' must not have refs')
|
|
261
268
|
invariant(!this._patches, this._name + ' must not have patches')
|
|
262
269
|
|
|
263
|
-
const prevState = this._state
|
|
264
|
-
|
|
265
270
|
const connection = this._handler._connection
|
|
266
271
|
if (this._subscribed && connection.connected) {
|
|
267
272
|
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, this._name)
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
this._subscribed = false
|
|
271
|
-
this._state
|
|
272
|
-
|
|
273
|
-
|
|
276
|
+
if (this._state > Record.STATE.CLIENT) {
|
|
277
|
+
this._state = Record.STATE.CLIENT
|
|
278
|
+
this._handler._onPending(this)
|
|
274
279
|
this._emitUpdate()
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
|
|
278
|
-
_subscribe() {
|
|
279
|
-
invariant(this._refs, this._name + ' missing refs')
|
|
280
|
-
|
|
281
|
-
const connection = this._handler._connection
|
|
282
|
-
if (!this._subscribed && connection.connected) {
|
|
283
|
-
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
284
|
-
this._subscribed = true
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
283
|
_update(nextData) {
|
|
289
284
|
if (nextData === this._data) {
|
|
290
285
|
return false
|
|
@@ -314,36 +309,36 @@ class Record {
|
|
|
314
309
|
_onUpdate([, version, data]) {
|
|
315
310
|
const prevData = this._data
|
|
316
311
|
const prevVersion = this._version
|
|
317
|
-
const prevState = this._state
|
|
318
312
|
|
|
319
313
|
if (this._updating?.delete(version)) {
|
|
320
314
|
this._handler._stats.updating -= 1
|
|
321
315
|
}
|
|
322
316
|
|
|
323
|
-
if (
|
|
317
|
+
if (
|
|
318
|
+
(version.charAt(0) === 'I' && this._version !== version) ||
|
|
319
|
+
utils.compareRev(version, this._version) > 0
|
|
320
|
+
) {
|
|
321
|
+
this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
|
|
324
322
|
this._version = version
|
|
325
|
-
|
|
323
|
+
}
|
|
326
324
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
for (let n = 0; n < this._patches.length; n += 2) {
|
|
330
|
-
patchData = jsonPath.set(patchData, this._patches[n + 0], this._patches[n + 1], false)
|
|
331
|
-
}
|
|
332
|
-
this._update(patchData)
|
|
333
|
-
}
|
|
325
|
+
invariant(this._version, 'must have version')
|
|
326
|
+
invariant(this._data, 'must have data')
|
|
334
327
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
this.
|
|
338
|
-
|
|
328
|
+
if (this._patches && this._version.charAt(0) !== 'I') {
|
|
329
|
+
let patchData = this._data
|
|
330
|
+
for (let n = 0; n < this._patches.length; n += 2) {
|
|
331
|
+
patchData = jsonPath.set(patchData, this._patches[n + 0], this._patches[n + 1], false)
|
|
332
|
+
}
|
|
333
|
+
this._update(patchData)
|
|
339
334
|
}
|
|
335
|
+
this._patches = null
|
|
340
336
|
|
|
341
337
|
if (this._state < Record.STATE.SERVER) {
|
|
342
338
|
this._state = this._version.charAt(0) === 'I' ? Record.STATE.STALE : Record.STATE.SERVER
|
|
343
339
|
this._handler._onPending(this)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (this._data !== prevData || this._version !== prevVersion || this._state !== prevState) {
|
|
340
|
+
this._emitUpdate()
|
|
341
|
+
} else if (this._data !== prevData || this._version !== prevVersion) {
|
|
347
342
|
this._emitUpdate()
|
|
348
343
|
}
|
|
349
344
|
}
|