@live-change/dao 0.4.4 → 0.4.5
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/ReactiveServerConnection.js +28 -25
- package/package.json +2 -2
|
@@ -3,6 +3,7 @@ const ObservableList = require("./ObservableList.js")
|
|
|
3
3
|
const utils = require('./utils.js')
|
|
4
4
|
const collectPointers = require('./collectPointers.js')
|
|
5
5
|
const debug = require("debug")("reactive-dao")
|
|
6
|
+
const debugPot = require("debug")("reactive-dao:pot")
|
|
6
7
|
|
|
7
8
|
class PushObservableTrigger {
|
|
8
9
|
constructor(po, what, more) {
|
|
@@ -28,44 +29,43 @@ class PushObservableTrigger {
|
|
|
28
29
|
),
|
|
29
30
|
remove: (value) => {
|
|
30
31
|
const valueJson = JSON.stringify(value)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
35
|
-
)
|
|
32
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v) == valueJson)
|
|
33
|
+
const oldPointers = this.findPointers(existingElements)
|
|
34
|
+
this.removePointers(oldPointers, [])
|
|
36
35
|
},
|
|
37
36
|
removeByField: (fieldName, value) => {
|
|
38
37
|
const valueJson = JSON.stringify(value)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
)
|
|
38
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
39
|
+
const oldPointers = this.findPointers(existingElements)
|
|
40
|
+
this.removePointers(oldPointers, [])
|
|
44
41
|
},
|
|
45
42
|
update: (value, update) => {
|
|
46
43
|
const valueJson = JSON.stringify(value)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.findPointers(
|
|
52
|
-
localList.list.filter(v => JSON.stringify(v) == valueJson).map(u => update)
|
|
53
|
-
)
|
|
54
|
-
)
|
|
44
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v) == valueJson)
|
|
45
|
+
const oldPointers = this.findPointers(existingElements)
|
|
46
|
+
const newPointers = this.findPointers(existingElements.map(u => update))
|
|
47
|
+
this.replacePointers(oldPointers, newPointers)
|
|
55
48
|
},
|
|
56
49
|
updateByField: (fieldName, value, update) => {
|
|
57
50
|
const valueJson = JSON.stringify(value)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
52
|
+
const oldPointers = this.findPointers(existingElements)
|
|
53
|
+
const newPointers = this.findPointers(existingElements.map(u => update))
|
|
54
|
+
this.replacePointers(oldPointers, newPointers)
|
|
55
|
+
},
|
|
56
|
+
putByField: (fieldName, value, update) => {
|
|
57
|
+
const valueJson = JSON.stringify(value)
|
|
58
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
59
|
+
const oldPointers = this.findPointers(existingElements)
|
|
60
|
+
const newPointers = this.findPointers(
|
|
61
|
+
existingElements.length > 0 ? existingElements.map(u => update) : [ update ]
|
|
65
62
|
)
|
|
63
|
+
console.log()
|
|
64
|
+
this.replacePointers(oldPointers, newPointers)
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
this.observer = (signal, ...args) => {
|
|
68
|
+
debugPot("POT", this.what, "UPDATE SIGNAL", signal, args)
|
|
69
69
|
if(this.pointerMethods[signal]) this.pointerMethods[signal](...args)
|
|
70
70
|
if(localList[signal]) localList[signal](...JSON.parse(JSON.stringify(args)))
|
|
71
71
|
}
|
|
@@ -74,6 +74,7 @@ class PushObservableTrigger {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
findPointers(value) {
|
|
77
|
+
debugPot("FIND POINTERS IN", value)
|
|
77
78
|
let depsPointers = []
|
|
78
79
|
let count = 0
|
|
79
80
|
for(let dep of this.more) {
|
|
@@ -87,6 +88,7 @@ class PushObservableTrigger {
|
|
|
87
88
|
what: pt,
|
|
88
89
|
more: dep.more
|
|
89
90
|
})
|
|
91
|
+
debugPot("FOUND POINTERS", allPointers)
|
|
90
92
|
return allPointers
|
|
91
93
|
}
|
|
92
94
|
setPointers(allPointers) {
|
|
@@ -100,6 +102,7 @@ class PushObservableTrigger {
|
|
|
100
102
|
this.commitPointersUpdate(added, removed)
|
|
101
103
|
}
|
|
102
104
|
replacePointers(oldPointers, newPointers) {
|
|
105
|
+
debugPot("REPLACE POINTERS", oldPointers, newPointers)
|
|
103
106
|
let added = []
|
|
104
107
|
let removed = []
|
|
105
108
|
for(let pointer of newPointers) {
|
package/package.json
CHANGED