@nxtedition/deepstream.io-client-js 24.0.3 → 24.0.4

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": "24.0.3",
3
+ "version": "24.0.4",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -90,8 +90,6 @@ class RecordHandler {
90
90
 
91
91
  this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
92
92
 
93
- this._pruningTimeout = null
94
-
95
93
  const _prune = () => {
96
94
  const pruning = this._pruning
97
95
  this._pruning = new Set()
@@ -105,24 +103,20 @@ class RecordHandler {
105
103
  this._stats.records -= pruning.size
106
104
  this._stats.destroyed += pruning.size
107
105
 
108
- if (this._pruningTimeout) {
109
- this._pruningTimeout.refresh()
110
- } else {
111
- this._pruningTimeout = timers.setTimeout(_prune, 1e3)
112
- }
106
+ this._pruningTimeout.refresh()
113
107
  }
114
108
 
115
- _prune()
109
+ this._pruningTimeout = timers.setTimeout(_prune, 1e3)
116
110
  }
117
111
 
118
- _onPruning(rec, isPruning) {
119
- if (isPruning) {
112
+ _onPruning(rec, value) {
113
+ if (value) {
120
114
  this._stats.pruning += 1
121
115
  } else {
122
116
  this._stats.pruning -= 1
123
117
  }
124
118
 
125
- if (isPruning) {
119
+ if (value) {
126
120
  this._pruning.add(rec)
127
121
  } else {
128
122
  this._pruning.delete(rec)
@@ -229,25 +223,11 @@ class RecordHandler {
229
223
 
230
224
  sync() {
231
225
  // TODO (fix): Sync patching & updating?
226
+ // TODO (fix): Ensure no pending?
232
227
  return new Promise((resolve) => {
233
- let counter = this._pending.size + 1
234
-
235
- const maybeSync = () => {
236
- counter -= 1
237
- if (counter > 0) {
238
- return
239
- }
240
-
241
- const token = xuid()
242
- this._syncEmitter.once(token, resolve)
243
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
244
- }
245
-
246
- for (const callbacks of this._pending.values()) {
247
- callbacks.push(maybeSync)
248
- }
249
-
250
- maybeSync()
228
+ const token = xuid()
229
+ this._syncEmitter.once(token, resolve)
230
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
251
231
  })
252
232
  }
253
233
 
@@ -314,12 +294,18 @@ class RecordHandler {
314
294
  * @returns {rxjs.Observable<{ name: string, version: string, state: Number, data: any}>}
315
295
  */
316
296
  observe2(...args) {
317
- return this._observe(null, ...args)
297
+ return this._observe(
298
+ {
299
+ timeout: 10 * 60e3,
300
+ },
301
+ ...args
302
+ )
318
303
  }
319
304
 
320
305
  /**
321
306
  * @returns {rxjs.Observable}
322
307
  */
308
+ // TODO (perf): Avoid rest parameters.
323
309
  _observe(defaults, name, ...args) {
324
310
  let path
325
311
  let state = defaults ? defaults.state : undefined
@@ -365,6 +351,7 @@ class RecordHandler {
365
351
  state = C.RECORD_STATE[state.toUpperCase()]
366
352
  }
367
353
 
354
+ // TODO (perf): Avoid subscribe closure allocation.
368
355
  return new rxjs.Observable((subscriber) => {
369
356
  const subscription = {
370
357
  subscriber,
@@ -396,19 +383,21 @@ class RecordHandler {
396
383
  },
397
384
  }
398
385
 
399
- subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
386
+ const record = (subscription.record = this.getRecord(name).subscribe(onUpdate, subscription))
400
387
 
401
- if (timeout && subscription.state && subscription.record.state < subscription.state) {
388
+ if (timeout && state && record.state < state) {
389
+ // TODO (perf): Avoid Timer allocation.
402
390
  subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
403
391
  }
404
392
 
405
- if (subscription.record.version) {
406
- onUpdate(subscription.record, subscription)
393
+ if (record.version) {
394
+ onUpdate(record, subscription)
407
395
  }
408
396
 
409
- if (subscription.signal) {
410
- subscription.abort = () => subscription.subscriber.error(new utils.AbortError())
411
- utils.addAbortListener(subscription.signal, subscription.abort)
397
+ if (signal) {
398
+ // TODO (perf): Avoid abort closure allocation.
399
+ subscription.abort = () => subscriber.error(new utils.AbortError())
400
+ utils.addAbortListener(signal, subscription.abort)
412
401
  }
413
402
 
414
403
  return subscription
@@ -19,8 +19,8 @@ class Record {
19
19
  this._refs = 0
20
20
  this._subscriptions = []
21
21
  this._emitting = false
22
- this._updating = null
23
- this._patching = null
22
+ /** @type Map? */ this._updating = null
23
+ /** @type Array? */ this._patching = null
24
24
  this._pending = false
25
25
  this._subscribed = this._sendMsg1(C.ACTIONS.SUBSCRIBE, this._name)
26
26
 
@@ -160,7 +160,11 @@ class Record {
160
160
  this._patching.splice(0)
161
161
  }
162
162
 
163
- this._patching.push(path, cloneDeep(data))
163
+ if (this._patching) {
164
+ this._patching.push(path, cloneDeep(data))
165
+ } else {
166
+ throw new Error('invalid state')
167
+ }
164
168
  } else {
165
169
  this._update(jsonPath.set(this._data, path, data, false))
166
170
  }
@@ -311,7 +315,11 @@ class Record {
311
315
  this._onUpdating(true)
312
316
  }
313
317
 
314
- this._updating.set(nextVersion, update)
318
+ if (this._updating) {
319
+ this._updating.set(nextVersion, update)
320
+ } else {
321
+ throw new Error('invalid state')
322
+ }
315
323
 
316
324
  connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
317
325
 
@@ -448,23 +456,15 @@ class Record {
448
456
 
449
457
  _emitUpdate() {
450
458
  this._emitting = true
451
- try {
452
- const arr = this._subscriptions
453
- const len = arr.length
454
-
455
- for (let n = 0; n < len; n += 2) {
456
- try {
457
- arr[n + 0](this, arr[n + 1])
458
- } catch (err) {
459
- this._error(
460
- C.EVENT.USER_ERROR,
461
- Object.assign(new Error('user callback failed'), { cause: err })
462
- )
463
- }
464
- }
465
- } finally {
466
- this._emitting = false
459
+
460
+ const arr = this._subscriptions
461
+ const len = arr.length
462
+
463
+ for (let n = 0; n < len; n += 2) {
464
+ arr[n + 0](this, arr[n + 1])
467
465
  }
466
+
467
+ this._emitting = false
468
468
  }
469
469
  }
470
470