@live-change/dao 0.9.83 → 0.9.85

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/index.js CHANGED
@@ -86,5 +86,8 @@ import Path from "./lib/Path.js"
86
86
  rd.Path = Path
87
87
  export { Path }
88
88
 
89
+ import { sourceSymbol } from "./lib/ReactiveConnection.js"
90
+ rd.sourceSymbol = sourceSymbol
91
+ export { sourceSymbol }
89
92
 
90
93
  export default rd
@@ -1,6 +1,7 @@
1
1
  import Debug from 'debug'
2
2
  const debug = Debug('reactive-dao:cache')
3
3
  import ObservableValue from "./ObservableValue.js"
4
+ import { sourceSymbol } from "./ReactiveConnection.js"
4
5
 
5
6
  class DaoPrerenderCache {
6
7
 
@@ -22,9 +23,12 @@ class DaoPrerenderCache {
22
23
  }
23
24
  }
24
25
  }
25
- for(const [what, observable] of this.observables.entries()) {
26
+ for(const [cacheKey, observable] of this.observables.entries()) {
26
27
  if(observable.isDisposed()) {
27
- observable.set(this.cache.get(what))
28
+ observable.set(this.cache.get(cacheKey))
29
+ if(this.extendedCache.has(cacheKey)) {
30
+ observable.restore(this.extendedCache.get(cacheKey))
31
+ }
28
32
  }
29
33
  }
30
34
  this.observables.clear()
@@ -40,14 +44,19 @@ class DaoPrerenderCache {
40
44
  }
41
45
  if(this.mode === 'save') {
42
46
  observable = new ObservableValue()
43
- this.get(what).then(value => observable.set(value)).catch(error => observable.error(error))
47
+ this.get(what).then(value => {
48
+ if(value && typeof value === 'object') value[sourceSymbol] = what
49
+ observable.set(value)
50
+ }).catch(error => observable.error(error))
44
51
  } else {
45
52
  observable = this.dao.observable(what)
46
53
  }
47
54
  this.observables.set(cacheKey, observable)
48
55
  if(this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey))
49
56
  if(this.extendedCache.has(cacheKey)) {
50
- observable.restore(this.extendedCache.get(cacheKey))
57
+ const data = this.extendedCache.get(cacheKey)
58
+ if(data && typeof data === 'object') data[sourceSymbol] = what
59
+ observable.restore(data)
51
60
  return observable
52
61
  // do not save extended values
53
62
  }
@@ -112,8 +121,11 @@ class DaoPrerenderCache {
112
121
  }
113
122
  })
114
123
  }
115
-
116
- return promise
124
+
125
+ return promise.then(data => {
126
+ if(data && typeof data === 'object') data[sourceSymbol] = what
127
+ return data
128
+ })
117
129
  }
118
130
 
119
131
  set(what, value) {
@@ -5,6 +5,8 @@ import * as utils from './utils.js'
5
5
 
6
6
  let lastUid = 0
7
7
 
8
+ export const sourceSymbol = Symbol("source")
9
+
8
10
  class Observation {
9
11
  constructor(connection, what, pushed) {
10
12
  this.what = what
@@ -23,10 +25,15 @@ class Observation {
23
25
  this.connection.sendObserve(this)
24
26
  }
25
27
  //process.nextTick(() => { // next tick will replay events through all layer to the client - it's waste of resources
26
- for(let { signal, args} of this.receivedSignals) {
28
+ for(let { signal, args } of this.receivedSignals) {
29
+ if(signal === "set" && args[0] && typeof args[0] === 'object') args[0][sourceSymbol] = this.what
27
30
  if(typeof observable == 'function') observable(signal, ...args)
28
31
  else if(observable.notify) observable.notify(signal, ...args)
29
32
  else observable[signal](...args)
33
+ if(signal === "set" && observable.getValue) {
34
+ const value = observable.getValue()
35
+ if(value && typeof value === 'object') value[sourceSymbol] = this.what
36
+ }
30
37
  }
31
38
  //})
32
39
  }
@@ -93,12 +100,17 @@ class Observation {
93
100
  }
94
101
  handleNotifyMessage({ signal, args }) {
95
102
  if(this.disposed) return
103
+ if(signal === "set" && args[0] && typeof args[0] === 'object') args[0][sourceSymbol] = this.what
96
104
  this.receivedSignals.push({ signal, args })
97
105
  for(let observable of this.observables) {
98
- utils.nextTick(function(){
106
+ utils.nextTick(() => {
99
107
  if(typeof observable == 'function') observable(signal, ...args)
100
108
  else if(observable.notify) observable.notify(signal, ...args)
101
- else observable[signal](...args)
109
+ else observable[signal](...args)
110
+ if(signal === "set" && observable.getValue) {
111
+ const value = observable.getValue()
112
+ if(value && typeof value === 'object') value[sourceSymbol] = this.what
113
+ }
102
114
  })
103
115
  }
104
116
  }
@@ -228,7 +240,10 @@ class Connection extends EventEmitter {
228
240
  type: 'get',
229
241
  what: what
230
242
  }
231
- return this.sendRequest(msg)
243
+ return this.sendRequest(msg).then(data => {
244
+ if(data && typeof data === 'object') data[sourceSymbol] = what
245
+ return data
246
+ })
232
247
  }
233
248
  getMore(what, more) {
234
249
  const msg={
package/package.json CHANGED
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "NODE_ENV=test tape tests/*"
37
37
  },
38
- "version": "0.9.83",
39
- "gitHead": "db3fcd19e6e3a47dda84d3906e697623f057713a"
38
+ "version": "0.9.85",
39
+ "gitHead": "126afb0aad3ab6e03aa5742726f429c95c46783a"
40
40
  }