@nxtedition/deepstream.io-client-js 23.4.39 → 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 +1 -1
- package/src/record/record-handler.js +18 -10
- package/src/record/record.js +6 -23
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
189
|
-
rec.
|
|
190
|
-
|
|
191
|
-
|
|
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
|
}
|
package/src/record/record.js
CHANGED
|
@@ -22,7 +22,8 @@ class Record {
|
|
|
22
22
|
this._subscriptionsEmitting = false
|
|
23
23
|
this._updating = null
|
|
24
24
|
this._patches = null
|
|
25
|
-
|
|
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.
|
|
52
|
+
return this._state < Record.STATE.SERVER
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
ref() {
|
|
@@ -127,9 +128,6 @@ class Record {
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
if (!this._version) {
|
|
130
|
-
if (!this._patches) {
|
|
131
|
-
this._handler._onPending(this)
|
|
132
|
-
}
|
|
133
131
|
this._patches = path && this._patches ? this._patches : []
|
|
134
132
|
this._patches.push(path, cloneDeep(data))
|
|
135
133
|
}
|
|
@@ -250,6 +248,7 @@ class Record {
|
|
|
250
248
|
} else {
|
|
251
249
|
this._subscribed = false
|
|
252
250
|
this._state = Record.STATE.CLIENT
|
|
251
|
+
this._handler._onPending(this)
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
if (this._state !== prevState) {
|
|
@@ -279,12 +278,6 @@ class Record {
|
|
|
279
278
|
_subscribe() {
|
|
280
279
|
invariant(this._refs, this._name + ' missing refs')
|
|
281
280
|
|
|
282
|
-
if (!this._pending) {
|
|
283
|
-
this._pending = true
|
|
284
|
-
this._handler._onPending(this)
|
|
285
|
-
this._emitUpdate()
|
|
286
|
-
}
|
|
287
|
-
|
|
288
281
|
const connection = this._handler._connection
|
|
289
282
|
if (!this._subscribed && connection.connected) {
|
|
290
283
|
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
@@ -322,7 +315,6 @@ class Record {
|
|
|
322
315
|
const prevData = this._data
|
|
323
316
|
const prevVersion = this._version
|
|
324
317
|
const prevState = this._state
|
|
325
|
-
const prevPending = this._pending
|
|
326
318
|
|
|
327
319
|
if (this._updating?.delete(version)) {
|
|
328
320
|
this._handler._stats.updating -= 1
|
|
@@ -346,21 +338,12 @@ class Record {
|
|
|
346
338
|
this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
|
|
347
339
|
}
|
|
348
340
|
|
|
349
|
-
if (this._pending) {
|
|
350
|
-
this._pending = false
|
|
351
|
-
this._handler._onPending(this)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
341
|
if (this._state < Record.STATE.SERVER) {
|
|
355
342
|
this._state = this._version.charAt(0) === 'I' ? Record.STATE.STALE : Record.STATE.SERVER
|
|
343
|
+
this._handler._onPending(this)
|
|
356
344
|
}
|
|
357
345
|
|
|
358
|
-
if (
|
|
359
|
-
this._data !== prevData ||
|
|
360
|
-
this._version !== prevVersion ||
|
|
361
|
-
this._state !== prevState ||
|
|
362
|
-
this._pending !== prevPending
|
|
363
|
-
) {
|
|
346
|
+
if (this._data !== prevData || this._version !== prevVersion || this._state !== prevState) {
|
|
364
347
|
this._emitUpdate()
|
|
365
348
|
}
|
|
366
349
|
}
|