@live-change/dao 0.8.13 → 0.8.15

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/Dao.js CHANGED
@@ -83,7 +83,7 @@ class Dao extends EventEmitter {
83
83
  }
84
84
 
85
85
  get(what) {
86
- let defn = this.findDefinition(what)
86
+ let defn = this.findDefinition(what)
87
87
  defn = this.prepareSource(defn)
88
88
  return defn.source.get(what)
89
89
  }
@@ -38,7 +38,7 @@ class DaoPrerenderCache {
38
38
  debug("OBSERVABLE EXISTS", cacheKey)
39
39
  return observable
40
40
  }
41
- if(this.mode == 'save') {
41
+ if(this.mode === 'save') {
42
42
  observable = new ObservableValue()
43
43
  this.get(what).then(value => observable.set(value)).catch(error => observable.error(error))
44
44
  } else {
@@ -52,12 +52,12 @@ class DaoPrerenderCache {
52
52
  // do not save extended values
53
53
  }
54
54
  if(observable.isInitialized && observable.isInitialized()) {
55
- if(this.mode == 'save') {
55
+ if(this.mode === 'save') {
56
56
  this.cache.set(cacheKey, observable.save())
57
57
  }
58
58
  return observable
59
59
  }
60
- if(this.mode == 'load') {
60
+ if(this.mode === 'load') {
61
61
  // if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey))
62
62
  // it was loaded earlier
63
63
  }
@@ -77,10 +77,11 @@ class DaoPrerenderCache {
77
77
  debug("GET FROM EXTENDED CACHE", cacheKey, " => ", value)
78
78
  return Promise.resolve(value)
79
79
  }
80
- if(this.mode == 'load') {
80
+ if(this.mode === 'load') {
81
81
  }
82
82
  const promise = this.dao.get(what)
83
- if(this.mode == 'save') {
83
+
84
+ if(this.mode === 'save') {
84
85
  if(!promise) throw new Error("GET NOT FOUND: "+what)
85
86
  promise.then(result => {
86
87
  let observable = this.observables.get(cacheKey)
@@ -111,6 +112,7 @@ class DaoPrerenderCache {
111
112
  }
112
113
  })
113
114
  }
115
+
114
116
  return promise
115
117
  }
116
118
 
@@ -61,12 +61,12 @@ class Observation {
61
61
  removeObservable(observable) {
62
62
  if(this.disposed) throw new Error(`observation ${JSON.stringify(this.what)} use after disposal`)
63
63
  let id = this.observables.indexOf(observable)
64
- if(id == -1) throw new Error("could not remove not existing observable")
64
+ if(id === -1) throw new Error("could not remove not existing observable")
65
65
  this.observables.splice(id, 1)
66
- if(this.connection.connected && this.observables.length == 0) {
66
+ if(this.connection.connected && this.observables.length === 0) {
67
67
  this.connection.sendUnobserve(this)
68
68
  }
69
- if(this.observables.length == 0 && !this.pushed) {
69
+ if(this.observables.length === 0 && !this.pushed) {
70
70
  const whatId = JSON.stringify(this.what)
71
71
  this.connection.observations.delete(whatId)
72
72
  this.disposed = true
@@ -76,7 +76,7 @@ class Observation {
76
76
  handleDisconnect() {
77
77
  if(this.disposed) throw new Error(`observation ${JSON.stringify(this.what)} use after disposal`)
78
78
  this.pushed = false
79
- if(this.observables.length == 0) {
79
+ if(this.observables.length === 0) {
80
80
  const whatId = JSON.stringify(this.what)
81
81
  this.connection.observations.delete(whatId)
82
82
  this.disposed = true
@@ -147,7 +147,7 @@ class Connection extends EventEmitter {
147
147
  this.waitingRequests.delete(msg.requestId)
148
148
  return reject(err)
149
149
  }
150
- if (resp.type == 'error') {
150
+ if (resp.type === 'error') {
151
151
  reject(resp.error)
152
152
  return false
153
153
  }
@@ -164,7 +164,7 @@ class Connection extends EventEmitter {
164
164
  this.requestsQueue.push(request)
165
165
  if(settings.requestSendTimeout && settings.requestSendTimeout < Infinity) {
166
166
  setTimeout(() => {
167
- if(queuedConnectionId == this.connectedCounter) {
167
+ if(queuedConnectionId === this.connectedCounter) {
168
168
  this.requestsQueue[queueId] = null
169
169
  reject('disconnected')
170
170
  }
@@ -186,7 +186,7 @@ class Connection extends EventEmitter {
186
186
  for(let i = 0; i < this.requestsQueue.length; i++) {
187
187
  let req = this.requestsQueue[i]
188
188
  if(!req) continue
189
- if(req.msg.requestId == msg.requestId) {
189
+ if(req.msg.requestId === msg.requestId) {
190
190
  const req = this.requestsQueue[i]
191
191
  this.requestsQueue[i] = null
192
192
  req.handler('timeout')
@@ -253,18 +253,18 @@ class Connection extends EventEmitter {
253
253
  }
254
254
 
255
255
  handleMessage(message) {
256
- if(message.type == "pong") {
256
+ if(message.type === "pong") {
257
257
  this.emit('pong', message)
258
258
  }
259
- if(message.type == "ping") {
259
+ if(message.type === "ping") {
260
260
  this.emit('ping', message)
261
261
  message.type = "pong"
262
262
  this.send(message)
263
263
  }
264
- if(message.type == "timeSync") {
264
+ if(message.type === "timeSync") {
265
265
  this.emit('timeSync', message)
266
266
  }
267
- if(message.type == "authenticationError") {
267
+ if(message.type === "authenticationError") {
268
268
  this.finished = true
269
269
  this.closeConnection()
270
270
  this.emit('authenticationError', message.error)
@@ -276,12 +276,12 @@ class Connection extends EventEmitter {
276
276
  request.handler(null, message)
277
277
  return
278
278
  }
279
- if(message.type == "notify") {
279
+ if(message.type === "notify") {
280
280
  const whatId = JSON.stringify(message.what)
281
281
  const observation = this.observations.get(whatId)
282
282
  if(observation) observation.handleNotifyMessage(message)
283
283
  }
284
- if(message.type == "push") {
284
+ if(message.type === "push") {
285
285
  const whatId = JSON.stringify(message.what)
286
286
  const observation = this.observations.get(whatId)
287
287
  if(observation) {
@@ -291,12 +291,12 @@ class Connection extends EventEmitter {
291
291
  this.observations.set(whatId, observation)
292
292
  }
293
293
  }
294
- if(message.type == "unpush") {
294
+ if(message.type === "unpush") {
295
295
  const whatId = JSON.stringify(message.what)
296
296
  const observation = this.observations.get(whatId)
297
297
  if(!observation || !observation.pushed) throw Error("observation that is not pushed can not be unpushed")
298
298
  observation.pushed = false
299
- if(observation.observables.length == 0) {
299
+ if(observation.observables.length === 0) {
300
300
  this.observations.delete(whatId)
301
301
  this.observations.disposed = true
302
302
  }
@@ -451,6 +451,9 @@ class Connection extends EventEmitter {
451
451
  dispose() {
452
452
  debug("DISPOSE REACTIVE CONNECTION")
453
453
  this.finished = true
454
+ this.waitingRequests = new Map()
455
+ this.requestsQueue = []
456
+ this.observations = new Map()
454
457
  for(const timeout of this.activeTimeouts) clearTimeout(timeout)
455
458
  }
456
459
 
package/package.json CHANGED
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "NODE_ENV=test tape tests/*"
37
37
  },
38
- "version": "0.8.13",
39
- "gitHead": "4453aa639a9fe1a857d93d73ebd28a82c97fdd87"
38
+ "version": "0.8.15",
39
+ "gitHead": "4897eefbf3ce9ace57630127da89503c71114563"
40
40
  }