@live-change/dao 0.3.6 → 0.3.10
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/DaoPrerenderCache.js
CHANGED
|
@@ -6,6 +6,7 @@ class DaoPrerenderCache {
|
|
|
6
6
|
constructor(dao, mode) {
|
|
7
7
|
this.dao = dao
|
|
8
8
|
this.cache = new Map()
|
|
9
|
+
this.extendedCache = new Map()
|
|
9
10
|
this.mode = mode
|
|
10
11
|
this.observables = new Map()
|
|
11
12
|
}
|
|
@@ -16,7 +17,7 @@ class DaoPrerenderCache {
|
|
|
16
17
|
const key = JSON.parse(keyJson)
|
|
17
18
|
if(key.paths) {
|
|
18
19
|
for(const { what, data } of value) {
|
|
19
|
-
this.
|
|
20
|
+
this.extendedCache.set(JSON.stringify(what), data)
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
}
|
|
@@ -43,7 +44,12 @@ class DaoPrerenderCache {
|
|
|
43
44
|
observable = this.dao.observable(what)
|
|
44
45
|
}
|
|
45
46
|
this.observables.set(cacheKey, observable)
|
|
46
|
-
if
|
|
47
|
+
if(this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey))
|
|
48
|
+
if(this.extendedCache.has(cacheKey)) {
|
|
49
|
+
observable.restore(this.extendedCache.get(cacheKey))
|
|
50
|
+
return observable
|
|
51
|
+
// do not save extended values
|
|
52
|
+
}
|
|
47
53
|
if(observable.isInitialized && observable.isInitialized()) {
|
|
48
54
|
if(this.mode == 'save') {
|
|
49
55
|
this.cache.set(cacheKey, observable.save())
|
|
@@ -51,7 +57,8 @@ class DaoPrerenderCache {
|
|
|
51
57
|
return observable
|
|
52
58
|
}
|
|
53
59
|
if(this.mode == 'load') {
|
|
54
|
-
//if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey))
|
|
60
|
+
// if (this.cache.has(cacheKey)) observable.restore(this.cache.get(cacheKey))
|
|
61
|
+
// it was loaded earlier
|
|
55
62
|
}
|
|
56
63
|
return observable
|
|
57
64
|
}
|
|
@@ -59,11 +66,16 @@ class DaoPrerenderCache {
|
|
|
59
66
|
get(what) {
|
|
60
67
|
const cacheKey = JSON.stringify(what)
|
|
61
68
|
debug("GET", cacheKey)
|
|
62
|
-
if
|
|
69
|
+
if(this.cache.has(cacheKey)) {
|
|
63
70
|
const value = this.cache.get(cacheKey)
|
|
64
71
|
debug("GET FROM CACHE", cacheKey, " => ", value)
|
|
65
72
|
return Promise.resolve(value)
|
|
66
73
|
}
|
|
74
|
+
if(this.extendedCache.has(cacheKey)) {
|
|
75
|
+
const value = this.extendedCache.get(cacheKey)
|
|
76
|
+
debug("GET FROM EXTENDED CACHE", cacheKey, " => ", value)
|
|
77
|
+
return Promise.resolve(value)
|
|
78
|
+
}
|
|
67
79
|
if(this.mode == 'load') {
|
|
68
80
|
}
|
|
69
81
|
const promise = this.dao.get(what)
|
|
@@ -72,13 +84,30 @@ class DaoPrerenderCache {
|
|
|
72
84
|
promise.then(result => {
|
|
73
85
|
let observable = this.observables.get(cacheKey)
|
|
74
86
|
if(observable) {
|
|
75
|
-
if(typeof observable == 'function')
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
if(typeof observable == 'function') {
|
|
88
|
+
observable('set', result)
|
|
89
|
+
} else if(observable.notify) {
|
|
90
|
+
observable.notify('set', result)
|
|
91
|
+
} else {
|
|
92
|
+
observable.set(result)
|
|
78
93
|
}
|
|
79
|
-
observable.set(result)
|
|
80
94
|
}
|
|
81
95
|
this.cache.set(cacheKey, result)
|
|
96
|
+
if(what.paths) {
|
|
97
|
+
for(const { what, data } of result) {
|
|
98
|
+
let observable = this.observables.get(cacheKey)
|
|
99
|
+
if(observable) {
|
|
100
|
+
if(typeof observable == 'function') {
|
|
101
|
+
observable('set', data)
|
|
102
|
+
} else if(observable.notify) {
|
|
103
|
+
observable.notify('set', data)
|
|
104
|
+
} else {
|
|
105
|
+
observable.set(data)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.extendedCache.set(JSON.stringify(what), data)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
82
111
|
})
|
|
83
112
|
}
|
|
84
113
|
return promise
|
|
@@ -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 =
|
|
14
|
+
this.valueActivator = valueActivator
|
|
15
15
|
|
|
16
16
|
this.savedError = null
|
|
17
17
|
this.properties = []
|
package/lib/ObservableProxy.js
CHANGED
|
@@ -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]
|
|
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
|
package/lib/collectPointers.js
CHANGED
|
@@ -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
|
|
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
|
|
51
|
+
many = many || list.many
|
|
52
52
|
}
|
|
53
53
|
let out = new Array(count)
|
|
54
54
|
out.many = many
|
package/package.json
CHANGED