@nxtedition/deepstream.io-client-js 23.4.33 → 23.4.35

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.33",
3
+ "version": "23.4.35",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -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._patch = new Set()
28
- this._prune = new Set()
27
+ this._pending = new Set()
28
+ this._pruning = new Set()
29
29
 
30
30
  this._connected = 0
31
31
  this._stats = {
@@ -48,53 +48,53 @@ class RecordHandler {
48
48
 
49
49
  this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
50
50
 
51
- this._pruneTimeout = null
51
+ this._pruningTimeout = null
52
52
 
53
53
  // TODO (perf): schedule & yield to avoid blocking event loop?
54
- const _pruneSome = () => {
55
- const prune = this._prune
54
+ const _prune = () => {
55
+ const prune = this._pruning
56
56
 
57
- this._prune = new Set()
57
+ this._pruning = new Set()
58
58
  for (const rec of prune) {
59
- invariant(!rec.pending && !rec.ref, 'cannot prune pending or referenced record')
59
+ invariant(!rec.pending && !rec.refs, 'cannot prune pending or referenced record')
60
60
  rec._unsubscribe()
61
61
  this._records.delete(rec.name)
62
62
  this._stats.destroyed++
63
63
  }
64
64
 
65
- if (this._pruneTimeout && this._pruneTimeout.refresh) {
66
- this._pruneTimeout.refresh()
65
+ if (this._pruningTimeout && this._pruningTimeout.refresh) {
66
+ this._pruningTimeout.refresh()
67
67
  } else {
68
- this._pruneTimeout = setTimeout(_pruneSome, 1e3)
69
- if (this._pruneTimeout.unref) {
70
- this._pruneTimeout.unref()
68
+ this._pruningTimeout = setTimeout(_prune, 1e3)
69
+ if (this._pruningTimeout.unref) {
70
+ this._pruningTimeout.unref()
71
71
  }
72
72
  }
73
73
  }
74
74
 
75
- _pruneSome()
75
+ _prune()
76
76
 
77
77
  this._syncAll = this._syncAll.bind(this)
78
78
  }
79
79
 
80
80
  _onRef(rec) {
81
81
  if (rec.refs === 0 && !rec.pending) {
82
- this._prune.add(rec)
82
+ this._pruning.add(rec)
83
83
  } else if (rec.refs === 1) {
84
- this._prune.delete(rec)
84
+ this._pruning.delete(rec)
85
85
  }
86
86
  }
87
87
 
88
88
  _onPending(rec) {
89
89
  if (!rec.pending) {
90
- this._patch.delete(rec)
90
+ this._pending.delete(rec)
91
91
  if (rec.refs === 0) {
92
- this._prune.add(rec)
92
+ this._pruning.add(rec)
93
93
  }
94
94
  } else {
95
- this._patch.add(rec)
95
+ this._pending.add(rec)
96
96
  if (rec.refs === 0) {
97
- this._prune.delete(rec)
97
+ this._pruning.delete(rec)
98
98
  }
99
99
  }
100
100
  }
@@ -108,8 +108,8 @@ class RecordHandler {
108
108
  ...this._stats,
109
109
  listeners: this._listeners.size,
110
110
  records: this._records.size,
111
- pruning: this._prune.size,
112
- pending: this._patch.size,
111
+ pruning: this._pruning.size,
112
+ pending: this._pending.size,
113
113
  }
114
114
  }
115
115
 
@@ -177,7 +177,7 @@ class RecordHandler {
177
177
  let token
178
178
  let timeoutHandle
179
179
 
180
- const records = [...this._patch]
180
+ const records = [...this._pending]
181
181
 
182
182
  const onDone = (val) => {
183
183
  if (done) {
@@ -21,7 +21,7 @@ class Record {
21
21
  this._subscriptions = []
22
22
  this._updating = null
23
23
  this._patches = null
24
- this._pruning = false
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._patches ? this._patches.length / 2 : 0
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.pending, this._name + ' must not have pending')
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
  }