@nxtedition/deepstream.io-client-js 23.4.26 → 23.4.28
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 +28 -37
- package/src/record/record.js +5 -2
package/package.json
CHANGED
|
@@ -24,11 +24,9 @@ class RecordHandler {
|
|
|
24
24
|
this._client = client
|
|
25
25
|
this._records = new Map()
|
|
26
26
|
this._listeners = new Map()
|
|
27
|
-
this._prune = new Map()
|
|
28
27
|
this._patch = new Set()
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
this._purging = false
|
|
28
|
+
this._prune = new Set()
|
|
29
|
+
|
|
32
30
|
this._connected = 0
|
|
33
31
|
this._stats = {
|
|
34
32
|
updating: 0,
|
|
@@ -46,57 +44,50 @@ class RecordHandler {
|
|
|
46
44
|
this.provide = this.provide.bind(this)
|
|
47
45
|
this.getRecord = this.getRecord.bind(this)
|
|
48
46
|
|
|
49
|
-
this._schedule = options.schedule ?? utils.schedule
|
|
50
|
-
|
|
51
47
|
this._client.on(C.EVENT.CONNECTED, this._onConnectionStateChange.bind(this))
|
|
52
48
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this._schedule(prune)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const prune = () => {
|
|
61
|
-
this._now = Date.now()
|
|
62
|
-
this._pruning = false
|
|
63
|
-
|
|
64
|
-
let counter = 0
|
|
65
|
-
for (const [rec, timestamp] of this._prune) {
|
|
66
|
-
if (this._now - timestamp < 1e3) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (rec.pending) {
|
|
71
|
-
continue
|
|
72
|
-
}
|
|
49
|
+
// TODO (perf): schedule & yield to avoid blocking event loop?
|
|
50
|
+
const _pruneSome = () => {
|
|
51
|
+
const prune = this._prune
|
|
73
52
|
|
|
53
|
+
this._prune = new Set()
|
|
54
|
+
for (const rec of prune) {
|
|
55
|
+
invariant(rec.pending === false && rec.refs === 0)
|
|
74
56
|
rec._unsubscribe()
|
|
75
|
-
|
|
76
57
|
this._records.delete(rec.name)
|
|
77
|
-
this._prune.delete(rec)
|
|
78
|
-
|
|
79
|
-
if (counter++ > 1024) {
|
|
80
|
-
_prune()
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
58
|
}
|
|
59
|
+
|
|
60
|
+
const prunetimeout = utils.setTimeout(() => _pruneSome, 1e3)
|
|
61
|
+
prunetimeout.unref?.()
|
|
84
62
|
}
|
|
85
63
|
|
|
86
|
-
|
|
87
|
-
this._pruneInterval.unref?.()
|
|
64
|
+
_pruneSome()
|
|
88
65
|
|
|
89
66
|
this._syncAll = this._syncAll.bind(this)
|
|
90
67
|
}
|
|
91
68
|
|
|
92
69
|
_onRef(rec) {
|
|
93
|
-
if (rec.refs === 0) {
|
|
94
|
-
this._prune.
|
|
70
|
+
if (rec.refs === 0 && !rec.pending) {
|
|
71
|
+
this._prune.add(rec)
|
|
95
72
|
} else if (rec.refs === 1) {
|
|
96
73
|
this._prune.delete(rec)
|
|
97
74
|
}
|
|
98
75
|
}
|
|
99
76
|
|
|
77
|
+
_onPending(rec) {
|
|
78
|
+
if (!rec.pending) {
|
|
79
|
+
this._patch.delete(rec)
|
|
80
|
+
if (rec.refs === 0) {
|
|
81
|
+
this._prune.add(rec)
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
this._patch.add(rec)
|
|
85
|
+
if (rec.refs === 0) {
|
|
86
|
+
this._prune.delete(rec)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
100
91
|
get connected() {
|
|
101
92
|
return Boolean(this._connected)
|
|
102
93
|
}
|
package/src/record/record.js
CHANGED
|
@@ -21,6 +21,7 @@ class Record {
|
|
|
21
21
|
this._subscriptions = []
|
|
22
22
|
this._updating = null
|
|
23
23
|
this._patches = null
|
|
24
|
+
this._pruning = false
|
|
24
25
|
|
|
25
26
|
this._subscribe()
|
|
26
27
|
}
|
|
@@ -115,9 +116,11 @@ class Record {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
if (!this._version) {
|
|
119
|
+
if (!this._patches) {
|
|
120
|
+
this._handler._onPending(this)
|
|
121
|
+
}
|
|
118
122
|
this._patches = path && this._patches ? this._patches : []
|
|
119
123
|
this._patches.push(path, cloneDeep(data))
|
|
120
|
-
this._handler._patch.add(this)
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
if (this._update(jsonPath.set(this._data, path, data, false))) {
|
|
@@ -315,7 +318,7 @@ class Record {
|
|
|
315
318
|
}
|
|
316
319
|
|
|
317
320
|
this._patches = null
|
|
318
|
-
this._handler.
|
|
321
|
+
this._handler._onPending(this)
|
|
319
322
|
} else if (version.charAt(0) === 'I' || utils.compareRev(version, this._version) > 0) {
|
|
320
323
|
this._version = version
|
|
321
324
|
this._data = jsonPath.set(this._data, null, jsonPath.parse(data), true)
|