@nxtedition/deepstream.io-client-js 23.4.27 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/deepstream.io-client-js",
3
- "version": "23.4.27",
3
+ "version": "23.4.28",
4
4
  "description": "the javascript client for deepstream.io",
5
5
  "homepage": "http://deepstream.io",
6
6
  "bugs": {
@@ -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._now = Date.now()
30
- this._pruning = false
31
- this._purging = false
28
+ this._prune = new Set()
29
+
32
30
  this._connected = 0
33
31
  this._stats = {
34
32
  updating: 0,
@@ -46,55 +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
- const _prune = () => {
54
- let counter = 0
55
- for (const [rec, timestamp] of this._prune) {
56
- if (rec.pending) {
57
- continue
58
- }
59
-
60
- if (this._now - timestamp < 1e3) {
61
- return
62
- }
49
+ // TODO (perf): schedule & yield to avoid blocking event loop?
50
+ const _pruneSome = () => {
51
+ const prune = this._prune
63
52
 
53
+ this._prune = new Set()
54
+ for (const rec of prune) {
55
+ invariant(rec.pending === false && rec.refs === 0)
64
56
  rec._unsubscribe()
65
-
66
57
  this._records.delete(rec.name)
67
- this._prune.delete(rec)
68
-
69
- if (counter++ > 2048) {
70
- this._schedule(_prune)
71
- return
72
- }
73
58
  }
74
59
 
75
- this._pruning = false
76
- this._now = Date.now()
60
+ const prunetimeout = utils.setTimeout(() => _pruneSome, 1e3)
61
+ prunetimeout.unref?.()
77
62
  }
78
63
 
79
- this._pruneInterval = utils.setInterval(() => {
80
- if (!this._pruning) {
81
- this._pruning = true
82
- this._schedule(_prune)
83
- }
84
- }, 1e3)
85
- this._pruneInterval.unref?.()
64
+ _pruneSome()
86
65
 
87
66
  this._syncAll = this._syncAll.bind(this)
88
67
  }
89
68
 
90
69
  _onRef(rec) {
91
- if (rec.refs === 0) {
92
- this._prune.set(rec, this._now)
70
+ if (rec.refs === 0 && !rec.pending) {
71
+ this._prune.add(rec)
93
72
  } else if (rec.refs === 1) {
94
73
  this._prune.delete(rec)
95
74
  }
96
75
  }
97
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
+
98
91
  get connected() {
99
92
  return Boolean(this._connected)
100
93
  }
@@ -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._patch.delete(this)
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)