@nxtedition/deepstream.io-client-js 23.4.52 → 23.4.53

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.52",
3
+ "version": "23.4.53",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -16,12 +16,17 @@ class Record {
16
16
  this._version = ''
17
17
  this._data = jsonPath.EMPTY
18
18
  this._state = Record.STATE.VOID
19
- this._refs = 0
19
+ this._refs = 1
20
20
  this._subscriptions = []
21
- this._subscriptionsEmitting = false
21
+ this._emitting = false
22
22
  this._updating = null
23
- this._patches = null
23
+ this._patching = null
24
+ this._pending = false
24
25
  this._subscribed = false
26
+
27
+ this._onPending(true)
28
+
29
+ this._subscribe()
25
30
  }
26
31
 
27
32
  get name() {
@@ -50,7 +55,7 @@ class Record {
50
55
  this._handler._onPruning(this, false)
51
56
  }
52
57
 
53
- if (this._refs === 1 && this._handler._connection.connected && !this._subscribed) {
58
+ if (!this._subscribed) {
54
59
  this._subscribe()
55
60
  }
56
61
 
@@ -59,7 +64,7 @@ class Record {
59
64
 
60
65
  unref() {
61
66
  invariant(this._refs > 0, 'missing refs')
62
- invariant(this._refs > 0 || !this._patches, 'must not have patches')
67
+ invariant(this._refs > 0 || !this._patching, 'must not have patches')
63
68
  invariant(this._refs > 0 || this._state >= Record.STATE.SERVER, 'must be ready')
64
69
 
65
70
  this._refs -= 1
@@ -71,9 +76,9 @@ class Record {
71
76
  }
72
77
 
73
78
  subscribe(fn) {
74
- if (this._subscriptionsEmitting) {
79
+ if (this._emitting) {
75
80
  this._subscriptions = this._subscriptions.slice()
76
- this._subscriptionsEmitting = false
81
+ this._emitting = false
77
82
  }
78
83
 
79
84
  this._subscriptions.push(fn)
@@ -82,9 +87,9 @@ class Record {
82
87
  }
83
88
 
84
89
  unsubscribe(fn) {
85
- if (this._subscriptionsEmitting) {
90
+ if (this._emitting) {
86
91
  this._subscriptions = this._subscriptions.slice()
87
- this._subscriptionsEmitting = false
92
+ this._emitting = false
88
93
  }
89
94
 
90
95
  const idx = this._subscriptions.indexOf(fn)
@@ -128,14 +133,14 @@ class Record {
128
133
  }
129
134
 
130
135
  if (this._state < Record.STATE.SERVER) {
131
- if (!this._patches) {
136
+ if (!this._patching) {
132
137
  this.ref()
133
- this._patches = []
138
+ this._patching = []
134
139
  } else if (path) {
135
- this._patches.splice(0)
140
+ this._patching.splice(0)
136
141
  }
137
142
 
138
- this._patches.push(path, cloneDeep(data))
143
+ this._patching.push(path, cloneDeep(data))
139
144
  } else {
140
145
  this._update(jsonPath.set(this._data, path, data, false))
141
146
  }
@@ -228,8 +233,8 @@ class Record {
228
233
  return true
229
234
  }
230
235
 
231
- _$onConnectionStateChange() {
232
- if (this._handler._connection.connected) {
236
+ _$onConnectionStateChange(connected) {
237
+ if (connected) {
233
238
  if (this._refs > 0) {
234
239
  this._subscribe()
235
240
  }
@@ -243,6 +248,10 @@ class Record {
243
248
  this._subscribed = false
244
249
  }
245
250
 
251
+ if (!this._pending) {
252
+ this._onPending(true)
253
+ }
254
+
246
255
  if (this._state > Record.STATE.CLIENT) {
247
256
  this._state = Record.STATE.CLIENT
248
257
  this._emitUpdate()
@@ -250,20 +259,21 @@ class Record {
250
259
  }
251
260
 
252
261
  _subscribe() {
262
+ if (!this._handler._connection.connected) {
263
+ return
264
+ }
265
+
253
266
  invariant(this._handler._connection.connected, 'must be connected')
254
267
 
255
268
  this._handler._connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
256
269
  this._subscribed = true
257
-
258
- this.ref()
259
- this._handler._onPending(this, true)
260
270
  }
261
271
 
262
272
  _$dispose() {
263
273
  invariant(!this._refs, 'must not have refs')
264
- invariant(!this._patches, 'must not have patches')
274
+ invariant(!this._patching, 'must not have patches')
265
275
  invariant(!this._updating, 'must not have updates')
266
- invariant(this.state >= C.RECORD_STATE.SERVER, 'must not be pending')
276
+ invariant(!this._pending, 'must not be pending')
267
277
  invariant(
268
278
  !this._subscribed || this._handler._connection.connected,
269
279
  'must be unsubscribed or connected'
@@ -334,23 +344,25 @@ class Record {
334
344
  invariant(this._version, 'must have version')
335
345
  invariant(this._data, 'must have data')
336
346
 
337
- if (this._patches) {
347
+ if (this._patching) {
338
348
  if (this._version.charAt(0) !== 'I') {
339
349
  let patchData = this._data
340
- for (let n = 0; n < this._patches.length; n += 2) {
341
- patchData = jsonPath.set(patchData, this._patches[n + 0], this._patches[n + 1], false)
350
+ for (let n = 0; n < this._patching.length; n += 2) {
351
+ patchData = jsonPath.set(patchData, this._patching[n + 0], this._patching[n + 1], false)
342
352
  }
343
353
  this._update(patchData)
344
354
  }
345
355
 
346
- this._patches = null
356
+ this._patching = null
347
357
  this.unref()
348
358
  }
349
359
 
350
360
  if (this._state < C.RECORD_STATE.SERVER) {
351
361
  this._state = this._version.charAt(0) === 'I' ? C.RECORD_STATE.STALE : C.RECORD_STATE.SERVER
352
- this._handler._onPending(this, false)
353
- this.unref()
362
+ }
363
+
364
+ if (this._pending) {
365
+ this._onPending(false)
354
366
  }
355
367
 
356
368
  if (this._state !== prevState || this._data !== prevData || this._version !== prevVersion) {
@@ -358,13 +370,30 @@ class Record {
358
370
  }
359
371
  }
360
372
 
373
+ _onPending(value) {
374
+ if (this._pending === value) {
375
+ return
376
+ }
377
+
378
+ this._pending = value
379
+ this._handler._onPending(this, value)
380
+
381
+ if (value) {
382
+ this.ref()
383
+ } else {
384
+ this.unref()
385
+ }
386
+ }
387
+
361
388
  _onSubscriptionHasProvider([, hasProvider]) {
389
+ if (this._state < C.RECORD_STATE.SERVER) {
390
+ return
391
+ }
392
+
362
393
  const prevState = this._state
363
394
 
364
395
  this._state =
365
- hasProvider &&
366
- messageParser.convertTyped(hasProvider, this._handler._client) &&
367
- this._state >= C.RECORD_STATE.SERVER
396
+ hasProvider && messageParser.convertTyped(hasProvider, this._handler._client)
368
397
  ? C.RECORD_STATE.PROVIDER
369
398
  : this._version.charAt(0) === 'I'
370
399
  ? C.RECORD_STATE.STALE
@@ -394,7 +423,7 @@ class Record {
394
423
  }
395
424
 
396
425
  _emitUpdate() {
397
- this._subscriptionsEmitting = true
426
+ this._emitting = true
398
427
  try {
399
428
  for (const fn of this._subscriptions) {
400
429
  try {
@@ -407,7 +436,7 @@ class Record {
407
436
  }
408
437
  }
409
438
  } finally {
410
- this._subscriptionsEmitting = false
439
+ this._emitting = false
411
440
  }
412
441
  }
413
442
  }