@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 +3 -0
- package/lib/DaoPrerenderCache.js +18 -6
- package/lib/ReactiveConnection.js +19 -4
- package/package.json +2 -2
package/index.js
CHANGED
package/lib/DaoPrerenderCache.js
CHANGED
|
@@ -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 [
|
|
26
|
+
for(const [cacheKey, observable] of this.observables.entries()) {
|
|
26
27
|
if(observable.isDisposed()) {
|
|
27
|
-
observable.set(this.cache.get(
|
|
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 =>
|
|
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
|
-
|
|
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(
|
|
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