@nxtedition/deepstream.io-client-js 23.4.41 → 23.4.43

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "23.4.41",
3
+ "version": "23.4.43",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -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 = Record.STATE.CLIENT
251
- this._handler._onPending(this)
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
- if (this._state !== prevState) {
255
- this._emitUpdate()
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 = Record.STATE.CLIENT
272
-
273
- if (this._state !== prevState) {
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,37 @@ 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 (this._patches) {
317
+ if (
318
+ version.charAt(0) === 'I'
319
+ ? this._version !== version
320
+ : utils.compareRev(version, this._version) > 0
321
+ ) {
322
+ this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
324
323
  this._version = version
325
- this._data = jsonPath.parse(data)
324
+ }
326
325
 
327
- if (this._version.charAt(0) !== 'I') {
328
- let patchData = this._data
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
- }
326
+ invariant(this._version, 'must have version')
327
+ invariant(this._data, 'must have data')
334
328
 
335
- this._patches = null
336
- } else if (version.charAt(0) === 'I' || utils.compareRev(version, this._version) > 0) {
337
- this._version = version
338
- this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
329
+ if (this._patches && this._version.charAt(0) !== 'I') {
330
+ let patchData = this._data
331
+ for (let n = 0; n < this._patches.length; n += 2) {
332
+ patchData = jsonPath.set(patchData, this._patches[n + 0], this._patches[n + 1], false)
333
+ }
334
+ this._update(patchData)
339
335
  }
336
+ this._patches = null
340
337
 
341
338
  if (this._state < Record.STATE.SERVER) {
342
339
  this._state = this._version.charAt(0) === 'I' ? Record.STATE.STALE : Record.STATE.SERVER
343
340
  this._handler._onPending(this)
344
- }
345
-
346
- if (this._data !== prevData || this._version !== prevVersion || this._state !== prevState) {
341
+ this._emitUpdate()
342
+ } else if (this._data !== prevData || this._version !== prevVersion) {
347
343
  this._emitUpdate()
348
344
  }
349
345
  }