@nxtedition/deepstream.io-client-js 23.4.43 → 23.4.45

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.43",
3
+ "version": "23.4.45",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -12,9 +12,10 @@ module.exports.CONNECTION_STATE.RECONNECTING = 'RECONNECTING'
12
12
  module.exports.RECORD_STATE = {}
13
13
  module.exports.RECORD_STATE.VOID = 0
14
14
  module.exports.RECORD_STATE.CLIENT = 1
15
- module.exports.RECORD_STATE.SERVER = 2
16
- module.exports.RECORD_STATE.STALE = 3
17
- module.exports.RECORD_STATE.PROVIDER = 4
15
+ module.exports.RECORD_STATE.PENDING = 2
16
+ module.exports.RECORD_STATE.SERVER = 3
17
+ module.exports.RECORD_STATE.STALE = 4
18
+ module.exports.RECORD_STATE.PROVIDER = 5
18
19
 
19
20
  module.exports.RECORD_STATE_NAME = []
20
21
  for (const [key, val] of Object.entries(module.exports.RECORD_STATE)) {
@@ -51,11 +51,13 @@ class RecordHandler {
51
51
 
52
52
  // TODO (perf): schedule & yield to avoid blocking event loop?
53
53
  const _prune = () => {
54
- const prune = this._pruning
54
+ const pruning = this._pruning
55
55
 
56
56
  this._pruning = new Set()
57
- for (const rec of prune) {
58
- invariant(!rec.pending && !rec.refs, 'cannot prune pending or referenced record')
57
+ for (const rec of pruning) {
58
+ invariant(rec.refs === 0, 'cannot prune referenced record')
59
+ invariant(!this._pending.has(rec), 'cannot prune pending record')
60
+
59
61
  rec._unsubscribe()
60
62
  this._records.delete(rec.name)
61
63
  this._stats.destroyed++
@@ -75,7 +77,7 @@ class RecordHandler {
75
77
  }
76
78
 
77
79
  _onRef(rec) {
78
- if (rec.refs === 0 && !rec.pending) {
80
+ if (rec.refs === 0 && !this._pending.has(rec)) {
79
81
  this._pruning.add(rec)
80
82
  } else if (rec.refs === 1) {
81
83
  this._pruning.delete(rec)
@@ -83,7 +85,7 @@ class RecordHandler {
83
85
  }
84
86
 
85
87
  _onPending(rec) {
86
- if (!rec.pending) {
88
+ if (rec.state > C.RECORD_STATE.PENDING) {
87
89
  this._pending.delete(rec)
88
90
  if (rec.refs === 0) {
89
91
  this._pruning.add(rec)
@@ -164,7 +166,11 @@ class RecordHandler {
164
166
  return new Promise((resolve) => {
165
167
  let counter = 0
166
168
 
167
- const doSync = () => {
169
+ const maybeSync = () => {
170
+ if (counter > 0) {
171
+ return
172
+ }
173
+
168
174
  const token = xuid()
169
175
  this._syncEmitter.once(token, resolve)
170
176
 
@@ -174,7 +180,7 @@ class RecordHandler {
174
180
  }
175
181
 
176
182
  const onUpdate = (rec) => {
177
- if (rec.pending) {
183
+ if (rec.state < C.RECORD_STATE.SERVER) {
178
184
  return
179
185
  }
180
186
 
@@ -182,22 +188,18 @@ class RecordHandler {
182
188
  rec.unref()
183
189
  counter -= 1
184
190
 
185
- if (counter > 0) {
186
- return
187
- }
188
-
189
- doSync()
191
+ maybeSync()
190
192
  }
191
193
 
192
- if (this._pending.size > 0) {
193
- for (const rec of this._pending) {
194
+ for (const rec of this._pending) {
195
+ if (rec.state < C.RECORD_STATE.SERVER) {
194
196
  rec.ref()
195
197
  rec.subscribe(onUpdate)
196
198
  counter += 1
197
199
  }
198
- } else {
199
- doSync()
200
200
  }
201
+
202
+ maybeSync()
201
203
  })
202
204
  }
203
205
 
@@ -48,10 +48,6 @@ class Record {
48
48
  return this._refs
49
49
  }
50
50
 
51
- get pending() {
52
- return this._state < Record.STATE.SERVER
53
- }
54
-
55
51
  ref() {
56
52
  this._refs += 1
57
53
  if (this._refs === 1) {
@@ -127,9 +123,10 @@ class Record {
127
123
  throw new Error('invalid argument: path')
128
124
  }
129
125
 
130
- if (!this._version) {
126
+ if (this._state < Record.STATE.SERVER) {
131
127
  this._patches = path && this._patches ? this._patches : []
132
128
  this._patches.push(path, cloneDeep(data))
129
+ this._state = Record.STATE.PENDING
133
130
  }
134
131
 
135
132
  if (this._update(jsonPath.set(this._data, path, data, false))) {