@nxtedition/deepstream.io-client-js 24.1.0 → 24.1.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
CHANGED
|
@@ -318,11 +318,14 @@ Connection.prototype._setState = function (state) {
|
|
|
318
318
|
return
|
|
319
319
|
}
|
|
320
320
|
this._state = state
|
|
321
|
+
this.emit(C.EVENT.CONNECTION_STATE_CHANGED, state)
|
|
321
322
|
this._client.emit(C.EVENT.CONNECTION_STATE_CHANGED, state)
|
|
322
323
|
|
|
323
324
|
if (state === C.CONNECTION_STATE.OPEN) {
|
|
325
|
+
this.emit(C.EVENT.CONNECTED, true)
|
|
324
326
|
this._client.emit(C.EVENT.CONNECTED, true)
|
|
325
327
|
} else if (state === C.CONNECTION_STATE.RECONNECTING || state === C.CONNECTION_STATE.CLOSED) {
|
|
328
|
+
this.emit(C.EVENT.CONNECTED, false)
|
|
326
329
|
this._client.emit(C.EVENT.CONNECTED, false)
|
|
327
330
|
}
|
|
328
331
|
}
|
package/src/record/record.js
CHANGED
|
@@ -10,6 +10,8 @@ class Record {
|
|
|
10
10
|
static STATE = C.RECORD_STATE
|
|
11
11
|
|
|
12
12
|
constructor(name, handler) {
|
|
13
|
+
const connection = handler._connection
|
|
14
|
+
|
|
13
15
|
this._handler = handler
|
|
14
16
|
|
|
15
17
|
this._name = name
|
|
@@ -21,7 +23,7 @@ class Record {
|
|
|
21
23
|
this._emitting = false
|
|
22
24
|
/** @type Map? */ this._updating = null
|
|
23
25
|
/** @type Array? */ this._patching = null
|
|
24
|
-
this._subscribed =
|
|
26
|
+
this._subscribed = connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/** @type {string} */
|
|
@@ -53,10 +55,13 @@ class Record {
|
|
|
53
55
|
* @returns {Record}
|
|
54
56
|
*/
|
|
55
57
|
ref() {
|
|
58
|
+
const connection = this._handler._connection
|
|
59
|
+
|
|
56
60
|
this._refs += 1
|
|
57
61
|
if (this._refs === 1) {
|
|
58
62
|
this._handler._onPruning(this, false)
|
|
59
|
-
this._subscribed =
|
|
63
|
+
this._subscribed =
|
|
64
|
+
this._subscribed || connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
60
65
|
}
|
|
61
66
|
return this
|
|
62
67
|
}
|
|
@@ -261,12 +266,15 @@ class Record {
|
|
|
261
266
|
}
|
|
262
267
|
|
|
263
268
|
_$onConnectionStateChange(connected) {
|
|
269
|
+
const connection = this._handler._connection
|
|
270
|
+
|
|
264
271
|
if (connected) {
|
|
265
|
-
this._subscribed =
|
|
272
|
+
this._subscribed =
|
|
273
|
+
this._refs > 0 && connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.SUBSCRIBE, this._name)
|
|
266
274
|
|
|
267
275
|
if (this._updating) {
|
|
268
276
|
for (const update of this._updating.values()) {
|
|
269
|
-
|
|
277
|
+
connection.sendMsg(C.TOPIC.RECORD, C.ACTIONS.UPDATE, update)
|
|
270
278
|
}
|
|
271
279
|
}
|
|
272
280
|
} else {
|
|
@@ -280,12 +288,14 @@ class Record {
|
|
|
280
288
|
}
|
|
281
289
|
|
|
282
290
|
_$dispose() {
|
|
291
|
+
const connection = this._handler._connection
|
|
292
|
+
|
|
283
293
|
invariant(!this._refs, 'must not have refs')
|
|
284
294
|
invariant(!this._patching, 'must not have patches')
|
|
285
295
|
invariant(!this._updating, 'must not have updates')
|
|
286
296
|
|
|
287
297
|
if (this._subscribed) {
|
|
288
|
-
|
|
298
|
+
connection.sendMsg1(C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, this._name)
|
|
289
299
|
this._subscribed = false
|
|
290
300
|
}
|
|
291
301
|
|
|
@@ -414,10 +424,6 @@ class Record {
|
|
|
414
424
|
}
|
|
415
425
|
}
|
|
416
426
|
|
|
417
|
-
_sendMsg1(action, data) {
|
|
418
|
-
return this._handler._connection.sendMsg1(C.TOPIC.RECORD, action, data)
|
|
419
|
-
}
|
|
420
|
-
|
|
421
427
|
_error(event, msgOrError, data) {
|
|
422
428
|
this._handler._client._$onError(C.TOPIC.RECORD, event, msgOrError, [
|
|
423
429
|
...(Array.isArray(data) ? data : []),
|
|
@@ -13,11 +13,11 @@ class Listener {
|
|
|
13
13
|
this._recursive = recursive
|
|
14
14
|
this._stringify = stringify || JSON.stringify
|
|
15
15
|
|
|
16
|
-
this._$onConnectionStateChange()
|
|
16
|
+
this._$onConnectionStateChange(this._connection.connected)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
get connected() {
|
|
20
|
-
return this.
|
|
20
|
+
return this._connection.connected
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
get stats() {
|
|
@@ -209,8 +209,8 @@ class Listener {
|
|
|
209
209
|
return true
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
_$onConnectionStateChange() {
|
|
213
|
-
if (
|
|
212
|
+
_$onConnectionStateChange(connected) {
|
|
213
|
+
if (connected) {
|
|
214
214
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern])
|
|
215
215
|
} else {
|
|
216
216
|
this._reset()
|
|
@@ -2,8 +2,34 @@ const C = require('../constants/constants')
|
|
|
2
2
|
const rx = require('rxjs/operators')
|
|
3
3
|
const rxjs = require('rxjs')
|
|
4
4
|
|
|
5
|
+
const PIPE = rxjs.pipe(
|
|
6
|
+
rx.map((value) => {
|
|
7
|
+
let data
|
|
8
|
+
if (value && typeof value === 'string') {
|
|
9
|
+
if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
|
|
10
|
+
throw new Error(`invalid value: ${value}`)
|
|
11
|
+
}
|
|
12
|
+
data = value
|
|
13
|
+
} else if (value && typeof value === 'object') {
|
|
14
|
+
data = JSON.stringify(value)
|
|
15
|
+
} else if (data != null) {
|
|
16
|
+
throw new Error(`invalid value: ${value}`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return data
|
|
20
|
+
}),
|
|
21
|
+
rx.distinctUntilChanged()
|
|
22
|
+
)
|
|
23
|
+
|
|
5
24
|
class Listener {
|
|
6
|
-
constructor(topic, pattern, callback, handler,
|
|
25
|
+
constructor(topic, pattern, callback, handler, opts) {
|
|
26
|
+
if (opts.recursive) {
|
|
27
|
+
throw new Error('invalid argument: recursive')
|
|
28
|
+
}
|
|
29
|
+
if (opts.stringify) {
|
|
30
|
+
throw new Error('invalid argument: stringify')
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
this._topic = topic
|
|
8
34
|
this._pattern = pattern
|
|
9
35
|
this._callback = callback
|
|
@@ -11,36 +37,12 @@ class Listener {
|
|
|
11
37
|
this._client = this._handler._client
|
|
12
38
|
this._connection = this._handler._connection
|
|
13
39
|
this._subscriptions = new Map()
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this._pipe = rxjs.pipe(
|
|
17
|
-
rx.map((value) => {
|
|
18
|
-
let data
|
|
19
|
-
if (value && typeof value === 'string') {
|
|
20
|
-
if (value.charAt(0) !== '{' && value.charAt(0) !== '[') {
|
|
21
|
-
throw new Error(`invalid value: ${value}`)
|
|
22
|
-
}
|
|
23
|
-
data = value
|
|
24
|
-
} else if (value && typeof value === 'object') {
|
|
25
|
-
data = this._stringify(value)
|
|
26
|
-
} else if (data != null) {
|
|
27
|
-
throw new Error(`invalid value: ${value}`)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return data
|
|
31
|
-
}),
|
|
32
|
-
rx.distinctUntilChanged()
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
this._$onConnectionStateChange()
|
|
36
|
-
|
|
37
|
-
if (recursive) {
|
|
38
|
-
throw new Error('invalid argument: recursive')
|
|
39
|
-
}
|
|
40
|
+
|
|
41
|
+
this._$onConnectionStateChange(this._connection.connected)
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
get connected() {
|
|
43
|
-
return this.
|
|
45
|
+
return this._connection.connected
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
get stats() {
|
|
@@ -84,7 +86,7 @@ class Listener {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
if (value$) {
|
|
87
|
-
const subscription = value$.pipe(
|
|
89
|
+
const subscription = value$.pipe(PIPE).subscribe({
|
|
88
90
|
next: (data) => {
|
|
89
91
|
if (data == null) {
|
|
90
92
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN_REJECT, [this._pattern, name])
|
|
@@ -122,8 +124,8 @@ class Listener {
|
|
|
122
124
|
return true
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
_$onConnectionStateChange() {
|
|
126
|
-
if (
|
|
127
|
+
_$onConnectionStateChange(connected) {
|
|
128
|
+
if (connected) {
|
|
127
129
|
this._connection.sendMsg(this._topic, C.ACTIONS.LISTEN, [this._pattern, 'U'])
|
|
128
130
|
} else {
|
|
129
131
|
this._reset()
|