@live-change/dao 0.4.4 → 0.4.7
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/DaoProxy.js +6 -4
- package/lib/ObservableProxy.js +9 -4
- package/lib/ReactiveServerConnection.js +28 -25
- package/package.json +3 -3
package/lib/DaoProxy.js
CHANGED
|
@@ -57,10 +57,12 @@ class DaoProxy extends EventEmitter {
|
|
|
57
57
|
const newObservable = this.observables.get(spath)
|
|
58
58
|
if(newObservable && newObservable !== observable) {
|
|
59
59
|
observable.observable = newObservable
|
|
60
|
-
} else if(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
} else if(!observable.observable || observable.observable.isDisposed()) {
|
|
61
|
+
if(this.dao) {
|
|
62
|
+
observable.observable = this.dao.observable(what)
|
|
63
|
+
} else {
|
|
64
|
+
observable.observable = null
|
|
65
|
+
}
|
|
64
66
|
}
|
|
65
67
|
oldRespawn.call(observable, ...args)
|
|
66
68
|
}
|
package/lib/ObservableProxy.js
CHANGED
|
@@ -91,13 +91,18 @@ class ObservableProxy extends Observable {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
bindProperty(object, property) {
|
|
94
|
-
if(this.isDisposed())
|
|
94
|
+
if(this.isDisposed()) {
|
|
95
|
+
debugger
|
|
96
|
+
this.respawn()
|
|
97
|
+
}
|
|
95
98
|
this.properties.push([object, property])
|
|
96
|
-
if(this.observable)
|
|
99
|
+
if(this.observable) {
|
|
100
|
+
this.observable.bindProperty(object, property)
|
|
101
|
+
}
|
|
97
102
|
}
|
|
98
103
|
unbindProperty(object, property) {
|
|
99
|
-
for(
|
|
100
|
-
|
|
104
|
+
for(let i = 0; i < this.properties.length; i++) {
|
|
105
|
+
const prop = this.properties[i]
|
|
101
106
|
if(prop[0] === object && prop[1] === property) {
|
|
102
107
|
this.properties.splice(i, 1)
|
|
103
108
|
if(this.observable) this.observable.unbindProperty(object, property)
|
|
@@ -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
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/live-change/live-change-dao.git"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"debug": "^4.3.
|
|
16
|
+
"debug": "^4.3.4"
|
|
17
17
|
},
|
|
18
18
|
"description": "live data access object",
|
|
19
19
|
"devDependencies": {
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"test": "NODE_ENV=test blue-tape tests/*"
|
|
37
37
|
},
|
|
38
|
-
"version": "0.4.
|
|
39
|
-
"gitHead": "
|
|
38
|
+
"version": "0.4.7",
|
|
39
|
+
"gitHead": "6ee48a9d467ee4d00e66cc4db5bb0591cb793287"
|
|
40
40
|
}
|