@live-change/dao 0.4.2 → 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 +47 -17
- 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) {
|
|
@@ -15,38 +16,65 @@ class PushObservableTrigger {
|
|
|
15
16
|
this.triggers = new Map()
|
|
16
17
|
|
|
17
18
|
if(this.more && this.more.length > 0) {
|
|
18
|
-
|
|
19
|
+
const localList = new ObservableList()
|
|
19
20
|
this.pointerMethods = {
|
|
20
21
|
set: (value) => this.setPointers(this.findPointers(value)),
|
|
21
22
|
push: (value) => this.addPointers(this.findPointers(value)),
|
|
22
23
|
unshift: (value) => this.addPointers(this.findPointers(value)),
|
|
23
|
-
shift: () => this.removePointers(this.findPointers(
|
|
24
|
-
pop: () => this.removePointers(this.findPointers(
|
|
24
|
+
shift: () => this.removePointers(this.findPointers(localList.list[0])),
|
|
25
|
+
pop: () => this.removePointers(this.findPointers(localList.list[localList.list.length - 1])),
|
|
25
26
|
splice: (at, count, ...add) => this.replacePointers(
|
|
26
|
-
this.findPointers(
|
|
27
|
+
this.findPointers(localList.list.slice(at, at + count)),
|
|
27
28
|
this.findPointers(add)
|
|
28
29
|
),
|
|
29
|
-
remove: (value) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
remove: (value) => {
|
|
31
|
+
const valueJson = JSON.stringify(value)
|
|
32
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v) == valueJson)
|
|
33
|
+
const oldPointers = this.findPointers(existingElements)
|
|
34
|
+
this.removePointers(oldPointers, [])
|
|
35
|
+
},
|
|
36
|
+
removeByField: (fieldName, value) => {
|
|
37
|
+
const valueJson = JSON.stringify(value)
|
|
38
|
+
const existingElements = localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
39
|
+
const oldPointers = this.findPointers(existingElements)
|
|
40
|
+
this.removePointers(oldPointers, [])
|
|
41
|
+
},
|
|
42
|
+
update: (value, update) => {
|
|
43
|
+
const valueJson = JSON.stringify(value)
|
|
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)
|
|
48
|
+
},
|
|
49
|
+
updateByField: (fieldName, value, update) => {
|
|
50
|
+
const valueJson = JSON.stringify(value)
|
|
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 ]
|
|
62
|
+
)
|
|
63
|
+
console.log()
|
|
64
|
+
this.replacePointers(oldPointers, newPointers)
|
|
65
|
+
}
|
|
40
66
|
}
|
|
41
67
|
this.observer = (signal, ...args) => {
|
|
42
|
-
|
|
43
|
-
if
|
|
68
|
+
debugPot("POT", this.what, "UPDATE SIGNAL", signal, args)
|
|
69
|
+
if(this.pointerMethods[signal]) this.pointerMethods[signal](...args)
|
|
70
|
+
if(localList[signal]) localList[signal](...JSON.parse(JSON.stringify(args)))
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
this.observation.observable.observe(this.observer)
|
|
47
74
|
}
|
|
48
75
|
}
|
|
49
76
|
findPointers(value) {
|
|
77
|
+
debugPot("FIND POINTERS IN", value)
|
|
50
78
|
let depsPointers = []
|
|
51
79
|
let count = 0
|
|
52
80
|
for(let dep of this.more) {
|
|
@@ -60,6 +88,7 @@ class PushObservableTrigger {
|
|
|
60
88
|
what: pt,
|
|
61
89
|
more: dep.more
|
|
62
90
|
})
|
|
91
|
+
debugPot("FOUND POINTERS", allPointers)
|
|
63
92
|
return allPointers
|
|
64
93
|
}
|
|
65
94
|
setPointers(allPointers) {
|
|
@@ -73,6 +102,7 @@ class PushObservableTrigger {
|
|
|
73
102
|
this.commitPointersUpdate(added, removed)
|
|
74
103
|
}
|
|
75
104
|
replacePointers(oldPointers, newPointers) {
|
|
105
|
+
debugPot("REPLACE POINTERS", oldPointers, newPointers)
|
|
76
106
|
let added = []
|
|
77
107
|
let removed = []
|
|
78
108
|
for(let pointer of newPointers) {
|
package/package.json
CHANGED