@nxtedition/deepstream.io-client-js 24.0.0 → 24.0.2
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 +12 -9
- package/src/record/record.js +22 -0
package/package.json
CHANGED
|
@@ -13,8 +13,6 @@ const timers = require('../utils/timers')
|
|
|
13
13
|
|
|
14
14
|
const kEmpty = Symbol('kEmpty')
|
|
15
15
|
|
|
16
|
-
function noop() {}
|
|
17
|
-
|
|
18
16
|
function onUpdate(record, subscription) {
|
|
19
17
|
if (subscription.state && record.state < subscription.state) {
|
|
20
18
|
return
|
|
@@ -172,6 +170,10 @@ class RecordHandler {
|
|
|
172
170
|
return this._stats
|
|
173
171
|
}
|
|
174
172
|
|
|
173
|
+
/**
|
|
174
|
+
* @param {string} name
|
|
175
|
+
* @returns {Record}
|
|
176
|
+
*/
|
|
175
177
|
getRecord(name) {
|
|
176
178
|
invariant(
|
|
177
179
|
typeof name === 'string' && name.length > 0 && name !== '[object Object]',
|
|
@@ -351,17 +353,18 @@ class RecordHandler {
|
|
|
351
353
|
dataOnly,
|
|
352
354
|
data: kEmpty,
|
|
353
355
|
timeout: null,
|
|
354
|
-
|
|
356
|
+
/** @type {Record?} */ record: null,
|
|
357
|
+
/** @type {Function?} */ abort: null,
|
|
355
358
|
unsubscribe() {
|
|
356
359
|
if (this.timeout) {
|
|
357
360
|
timers.clearTimeout(this.timeout)
|
|
358
361
|
this.timeout = null
|
|
359
362
|
}
|
|
360
363
|
|
|
361
|
-
if (this.
|
|
364
|
+
if (this.signal) {
|
|
362
365
|
utils.removeAbortListener(this.signal, this.abort)
|
|
363
366
|
this.signal = null
|
|
364
|
-
this.abort =
|
|
367
|
+
this.abort = null
|
|
365
368
|
}
|
|
366
369
|
|
|
367
370
|
if (this.record) {
|
|
@@ -372,14 +375,14 @@ class RecordHandler {
|
|
|
372
375
|
},
|
|
373
376
|
}
|
|
374
377
|
|
|
375
|
-
|
|
378
|
+
subscription.record = this.getRecord(name).subscribe(onUpdate, subscription)
|
|
376
379
|
|
|
377
|
-
if (timeout && subscription.state && record.state < subscription.state) {
|
|
380
|
+
if (timeout && subscription.state && subscription.record.state < subscription.state) {
|
|
378
381
|
subscription.timeout = timers.setTimeout(onTimeout, timeout, subscription)
|
|
379
382
|
}
|
|
380
383
|
|
|
381
|
-
if (record.version) {
|
|
382
|
-
onUpdate(record, subscription)
|
|
384
|
+
if (subscription.record.version) {
|
|
385
|
+
onUpdate(subscription.record, subscription)
|
|
383
386
|
}
|
|
384
387
|
|
|
385
388
|
if (subscription.signal) {
|
package/src/record/record.js
CHANGED
|
@@ -27,26 +27,34 @@ class Record {
|
|
|
27
27
|
this._onPending(true)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** @type {string} */
|
|
30
31
|
get name() {
|
|
31
32
|
return this._name
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** @type {string} */
|
|
34
36
|
get version() {
|
|
35
37
|
return this._version
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
/** @type {Object} */
|
|
38
41
|
get data() {
|
|
39
42
|
return this._data
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
/** @type {Number} */
|
|
42
46
|
get state() {
|
|
43
47
|
return this._state
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
/** @type {Number} */
|
|
46
51
|
get refs() {
|
|
47
52
|
return this._refs
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @returns {Record}
|
|
57
|
+
*/
|
|
50
58
|
ref() {
|
|
51
59
|
this._refs += 1
|
|
52
60
|
if (this._refs === 1) {
|
|
@@ -56,6 +64,9 @@ class Record {
|
|
|
56
64
|
return this
|
|
57
65
|
}
|
|
58
66
|
|
|
67
|
+
/**
|
|
68
|
+
* @returns {Record}
|
|
69
|
+
*/
|
|
59
70
|
unref() {
|
|
60
71
|
this._refs -= 1
|
|
61
72
|
if (this._refs === 0) {
|
|
@@ -64,6 +75,11 @@ class Record {
|
|
|
64
75
|
return this
|
|
65
76
|
}
|
|
66
77
|
|
|
78
|
+
/**
|
|
79
|
+
* @param {*} fn
|
|
80
|
+
* @param {*} opaque
|
|
81
|
+
* @returns {Record}
|
|
82
|
+
*/
|
|
67
83
|
subscribe(fn, opaque = null) {
|
|
68
84
|
if (this._emitting) {
|
|
69
85
|
this._subscriptions = this._subscriptions.slice()
|
|
@@ -75,6 +91,12 @@ class Record {
|
|
|
75
91
|
return this
|
|
76
92
|
}
|
|
77
93
|
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param {*} fn
|
|
97
|
+
* @param {*} opaque
|
|
98
|
+
* @returns {Record}
|
|
99
|
+
*/
|
|
78
100
|
unsubscribe(fn, opaque = null) {
|
|
79
101
|
if (this._emitting) {
|
|
80
102
|
this._subscriptions = this._subscriptions.slice()
|