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

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.40",
3
+ "version": "23.4.41",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -164,6 +164,15 @@ class RecordHandler {
164
164
  return new Promise((resolve) => {
165
165
  let counter = 0
166
166
 
167
+ const doSync = () => {
168
+ const token = xuid()
169
+ this._syncEmitter.once(token, resolve)
170
+
171
+ if (this._connected) {
172
+ this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
173
+ }
174
+ }
175
+
167
176
  const onUpdate = (rec) => {
168
177
  if (rec.pending) {
169
178
  return
@@ -177,18 +186,17 @@ class RecordHandler {
177
186
  return
178
187
  }
179
188
 
180
- const token = xuid()
181
- this._syncEmitter.once(token, resolve)
182
-
183
- if (this._connected) {
184
- this._connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.SYNC, [token])
185
- }
189
+ doSync()
186
190
  }
187
191
 
188
- for (const rec of this._pending) {
189
- rec.ref()
190
- rec.subscribe(onUpdate)
191
- counter += 1
192
+ if (this._pending.size > 0) {
193
+ for (const rec of this._pending) {
194
+ rec.ref()
195
+ rec.subscribe(onUpdate)
196
+ counter += 1
197
+ }
198
+ } else {
199
+ doSync()
192
200
  }
193
201
  })
194
202
  }
@@ -22,7 +22,8 @@ class Record {
22
22
  this._subscriptionsEmitting = false
23
23
  this._updating = null
24
24
  this._patches = null
25
- this._pending = false
25
+
26
+ this._handler._onPending(this)
26
27
 
27
28
  this._subscribe()
28
29
  }
@@ -48,7 +49,7 @@ class Record {
48
49
  }
49
50
 
50
51
  get pending() {
51
- return this._pending
52
+ return this._state < Record.STATE.SERVER
52
53
  }
53
54
 
54
55
  ref() {
@@ -247,6 +248,7 @@ class Record {
247
248
  } else {
248
249
  this._subscribed = false
249
250
  this._state = Record.STATE.CLIENT
251
+ this._handler._onPending(this)
250
252
  }
251
253
 
252
254
  if (this._state !== prevState) {
@@ -276,12 +278,6 @@ class Record {
276
278
  _subscribe() {
277
279
  invariant(this._refs, this._name + ' missing refs')
278
280
 
279
- if (!this._pending) {
280
- this._pending = true
281
- this._handler._onPending(this)
282
- this._emitUpdate()
283
- }
284
-
285
281
  const connection = this._handler._connection
286
282
  if (!this._subscribed && connection.connected) {
287
283
  connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
@@ -319,7 +315,6 @@ class Record {
319
315
  const prevData = this._data
320
316
  const prevVersion = this._version
321
317
  const prevState = this._state
322
- const prevPending = this._pending
323
318
 
324
319
  if (this._updating?.delete(version)) {
325
320
  this._handler._stats.updating -= 1
@@ -343,21 +338,12 @@ class Record {
343
338
  this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
344
339
  }
345
340
 
346
- if (this._pending) {
347
- this._pending = false
348
- this._handler._onPending(this)
349
- }
350
-
351
341
  if (this._state < Record.STATE.SERVER) {
352
342
  this._state = this._version.charAt(0) === 'I' ? Record.STATE.STALE : Record.STATE.SERVER
343
+ this._handler._onPending(this)
353
344
  }
354
345
 
355
- if (
356
- this._data !== prevData ||
357
- this._version !== prevVersion ||
358
- this._state !== prevState ||
359
- this._pending !== prevPending
360
- ) {
346
+ if (this._data !== prevData || this._version !== prevVersion || this._state !== prevState) {
361
347
  this._emitUpdate()
362
348
  }
363
349
  }