@live-change/dao 0.3.7 → 0.3.11

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/lib/DaoCache.js CHANGED
@@ -83,6 +83,12 @@ class CacheState {
83
83
  }
84
84
  this.updateCacheState()
85
85
  }
86
+
87
+ dipose() {
88
+ if(this.cached) {
89
+ this.observable.unobserve(this.cache.dummyObserver)
90
+ }
91
+ }
86
92
  }
87
93
 
88
94
  const defaultSettings = {
@@ -133,6 +139,12 @@ class DaoCache extends EventEmitter {
133
139
  this.dummyObserver = () => 0
134
140
  }
135
141
 
142
+ clear() {
143
+ for(const [key, value] of this.cacheState.entries()) {
144
+ value.dispose()
145
+ this.cacheState.delete(key)
146
+ }
147
+ }
136
148
 
137
149
  clean() {
138
150
  //console.log("CACHE STATE:", this.cacheState)
@@ -165,6 +177,7 @@ class DaoCache extends EventEmitter {
165
177
  }
166
178
  for(const [key, value] of this.cacheState.entries()) {
167
179
  if(value.score < value.settings.deleteStatsScore) {
180
+ this.cacheState.dispose()
168
181
  this.cacheState.delete(key)
169
182
  }
170
183
  }
@@ -253,6 +266,7 @@ class DaoCache extends EventEmitter {
253
266
  }
254
267
 
255
268
  dispose() {
269
+ clear()
256
270
  clearInterval(this.interval)
257
271
  this.dao.dispose()
258
272
  }
@@ -1,17 +1,17 @@
1
1
  const ObservableList = require("./ObservableList.js")
2
2
 
3
3
  class ExtendedObservableList extends ObservableList {
4
- constructor(observableList, elementActivator, elementDispose) {
4
+ constructor(observableList, elementActivator, elementDispose, valueActivator = observableList.valueActivator) {
5
5
  let list = observableList.list
6
6
  if(elementActivator) {
7
7
  list = Array.isArray(list) ? list.map(elementActivator) : elementActivator(list)
8
8
  }
9
- super(list)
9
+ super(list, undefined, undefined, valueActivator)
10
10
 
11
11
  this.observableList = observableList
12
12
  this.elementActivator = elementActivator
13
13
  this.elementDispose = elementDispose
14
- this.valueActivator = observableList.valueActivator
14
+ this.valueActivator = valueActivator
15
15
 
16
16
  this.savedError = null
17
17
  this.properties = []
@@ -56,7 +56,7 @@ class LoopbackConnection extends Connection {
56
56
  }
57
57
 
58
58
  dispose() {
59
- this.finished = true
59
+ super.dispose()
60
60
  this.handleDisconnect()
61
61
  this.emit('close')
62
62
  }
@@ -15,6 +15,7 @@ class ObservableProxy extends Observable {
15
15
  }
16
16
 
17
17
  setTarget(observable) {
18
+ if(this === observable) throw new Error('infinite loop')
18
19
  if(!this.disposed && this.observable) {
19
20
  this.observable.unobserve(this.observer)
20
21
  for(let [object, property] of this.properties) {
@@ -80,8 +81,8 @@ class ObservableProxy extends Observable {
80
81
  unbindProperty(object, property) {
81
82
  for(var i = 0; i < this.properties.length; i++) {
82
83
  var prop = this.properties[i]
83
- if(prop[0] == object && prop[1] == property) {
84
- this.properties.splice(i,1)
84
+ if(prop[0] === object && prop[1] === property) {
85
+ this.properties.splice(i, 1)
85
86
  if(this.observable) this.observable.unbindProperty(object, property)
86
87
  if(this.isUseless()) this.dispose()
87
88
  return
@@ -123,6 +123,8 @@ class Connection extends EventEmitter {
123
123
  this.remoteObserveSent = new Map()
124
124
  this.remoteUnobserveSent = new Map()
125
125
 
126
+ this.activeTimeouts = new Set()
127
+
126
128
  this.autoReconnect = true
127
129
 
128
130
  this.finished = false
@@ -173,7 +175,8 @@ class Connection extends EventEmitter {
173
175
  }
174
176
 
175
177
  if (settings.requestTimeout && settings.requestTimeout < Infinity) {
176
- setTimeout(() => {
178
+ const timeout = setTimeout(() => {
179
+ this.activeTimeouts.delete(timeout)
177
180
  let waiting = this.waitingRequests.get(msg.requestId)
178
181
  if (waiting) {
179
182
  waiting.handler('timeout')
@@ -189,6 +192,7 @@ class Connection extends EventEmitter {
189
192
  }
190
193
  }
191
194
  }, settings.requestTimeout)
195
+ this.activeTimeouts.add(timeout)
192
196
  }
193
197
 
194
198
  if(this.connected) {
@@ -443,6 +447,12 @@ class Connection extends EventEmitter {
443
447
  })
444
448
  }
445
449
 
450
+ dispose() {
451
+ console.log("DISPOSE REACTIVE CONNECTION")
452
+ this.finished = true
453
+ for(const timeout of this.activeTimeouts) clearTimeout(timeout)
454
+ }
455
+
446
456
  }
447
457
 
448
458
  module.exports = Connection
@@ -4,7 +4,7 @@ function flatMap(source, fun) {
4
4
  let many = source.many
5
5
  for(let result of results) {
6
6
  count += result.length
7
- many ||= result.many
7
+ many = many || result.many
8
8
  }
9
9
  if(count > 1 && !many) throw new Error("too many results from not many")
10
10
  let out = new Array(count)
@@ -48,7 +48,7 @@ function cross(lists) {
48
48
  let many = false
49
49
  for(let list of lists) {
50
50
  count *= list.length
51
- many ||= list.many
51
+ many = many || list.many
52
52
  }
53
53
  let out = new Array(count)
54
54
  out.many = many
package/package.json CHANGED
@@ -36,5 +36,5 @@
36
36
  "scripts": {
37
37
  "test": "NODE_ENV=test blue-tape tests/*"
38
38
  },
39
- "version": "0.3.7"
39
+ "version": "0.3.11"
40
40
  }