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

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.44",
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 = 3
16
+ module.exports.RECORD_STATE.SERVER = 4
17
+ module.exports.RECORD_STATE.STALE = 5
18
+ module.exports.RECORD_STATE.PROVIDER = 6
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,12 @@ 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, 'cannot prune referenced record')
59
+ invariant(rec.state !== C.RECORD_STATE.PENDING, 'cannot prune pending record')
59
60
  rec._unsubscribe()
60
61
  this._records.delete(rec.name)
61
62
  this._stats.destroyed++
@@ -75,7 +76,7 @@ class RecordHandler {
75
76
  }
76
77
 
77
78
  _onRef(rec) {
78
- if (rec.refs === 0 && !rec.pending) {
79
+ if (rec.refs === 0 && rec.state > C.RECORD_STATE.PENDING) {
79
80
  this._pruning.add(rec)
80
81
  } else if (rec.refs === 1) {
81
82
  this._pruning.delete(rec)
@@ -83,7 +84,7 @@ class RecordHandler {
83
84
  }
84
85
 
85
86
  _onPending(rec) {
86
- if (!rec.pending) {
87
+ if (rec.state > C.RECORD_STATE.PENDING) {
87
88
  this._pending.delete(rec)
88
89
  if (rec.refs === 0) {
89
90
  this._pruning.add(rec)
@@ -164,7 +165,11 @@ class RecordHandler {
164
165
  return new Promise((resolve) => {
165
166
  let counter = 0
166
167
 
167
- const doSync = () => {
168
+ const maybeSync = () => {
169
+ if (counter > 0) {
170
+ return
171
+ }
172
+
168
173
  const token = xuid()
169
174
  this._syncEmitter.once(token, resolve)
170
175
 
@@ -174,7 +179,7 @@ class RecordHandler {
174
179
  }
175
180
 
176
181
  const onUpdate = (rec) => {
177
- if (rec.pending) {
182
+ if (rec.state < C.RECORD_STATE.SERVER) {
178
183
  return
179
184
  }
180
185
 
@@ -182,22 +187,18 @@ class RecordHandler {
182
187
  rec.unref()
183
188
  counter -= 1
184
189
 
185
- if (counter > 0) {
186
- return
187
- }
188
-
189
- doSync()
190
+ maybeSync()
190
191
  }
191
192
 
192
- if (this._pending.size > 0) {
193
- for (const rec of this._pending) {
193
+ for (const rec of this._pending) {
194
+ if (rec.state < C.RECORD_STATE.SERVER) {
194
195
  rec.ref()
195
196
  rec.subscribe(onUpdate)
196
197
  counter += 1
197
198
  }
198
- } else {
199
- doSync()
200
199
  }
200
+
201
+ maybeSync()
201
202
  })
202
203
  }
203
204
 
@@ -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))) {