@live-change/dao 0.4.1 → 0.4.4
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/Dao.js +5 -1
- package/lib/ReactiveServerConnection.js +44 -17
- package/package.json +4 -4
package/lib/Dao.js
CHANGED
|
@@ -25,7 +25,11 @@ class Dao extends EventEmitter {
|
|
|
25
25
|
const protocol = this.definition.protocols[proto]
|
|
26
26
|
if(!protocol) throw new Error("Protocol "+proto+" not supported")
|
|
27
27
|
debug("connecting to "+url)
|
|
28
|
-
|
|
28
|
+
try {
|
|
29
|
+
connection = new protocol(this.credentials, url, this.definition.connectionSettings)
|
|
30
|
+
} catch(e) {
|
|
31
|
+
connection = protocol(this.credentials, url, this.definition.connectionSettings)
|
|
32
|
+
}
|
|
29
33
|
this.connections.set(connectionId, connection)
|
|
30
34
|
|
|
31
35
|
connection.on('connect', (...args) => this.emit('connect', connection, ...args))
|
|
@@ -15,32 +15,59 @@ class PushObservableTrigger {
|
|
|
15
15
|
this.triggers = new Map()
|
|
16
16
|
|
|
17
17
|
if(this.more && this.more.length > 0) {
|
|
18
|
-
|
|
18
|
+
const localList = new ObservableList()
|
|
19
19
|
this.pointerMethods = {
|
|
20
20
|
set: (value) => this.setPointers(this.findPointers(value)),
|
|
21
21
|
push: (value) => this.addPointers(this.findPointers(value)),
|
|
22
22
|
unshift: (value) => this.addPointers(this.findPointers(value)),
|
|
23
|
-
shift: () => this.removePointers(this.findPointers(
|
|
24
|
-
pop: () => this.removePointers(this.findPointers(
|
|
23
|
+
shift: () => this.removePointers(this.findPointers(localList.list[0])),
|
|
24
|
+
pop: () => this.removePointers(this.findPointers(localList.list[localList.list.length - 1])),
|
|
25
25
|
splice: (at, count, ...add) => this.replacePointers(
|
|
26
|
-
this.findPointers(
|
|
26
|
+
this.findPointers(localList.list.slice(at, at + count)),
|
|
27
27
|
this.findPointers(add)
|
|
28
28
|
),
|
|
29
|
-
remove: (value) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
remove: (value) => {
|
|
30
|
+
const valueJson = JSON.stringify(value)
|
|
31
|
+
this.removePointers(
|
|
32
|
+
this.findPointers(
|
|
33
|
+
localList.list.filter(v => JSON.stringify(v) == valueJson)
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
},
|
|
37
|
+
removeByField: (fieldName, value) => {
|
|
38
|
+
const valueJson = JSON.stringify(value)
|
|
39
|
+
this.removePointers(
|
|
40
|
+
this.findPointers(
|
|
41
|
+
localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
},
|
|
45
|
+
update: (value, update) => {
|
|
46
|
+
const valueJson = JSON.stringify(value)
|
|
47
|
+
this.replacePointers(
|
|
48
|
+
this.findPointers(
|
|
49
|
+
localList.list.filter(v => JSON.stringify(v) == valueJson)
|
|
50
|
+
),
|
|
51
|
+
this.findPointers(
|
|
52
|
+
localList.list.filter(v => JSON.stringify(v) == valueJson).map(u => update)
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
},
|
|
56
|
+
updateByField: (fieldName, value, update) => {
|
|
57
|
+
const valueJson = JSON.stringify(value)
|
|
58
|
+
this.replacePointers(
|
|
59
|
+
this.findPointers(
|
|
60
|
+
localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson)
|
|
61
|
+
),
|
|
62
|
+
this.findPointers(
|
|
63
|
+
localList.list.filter(v => JSON.stringify(v[fieldName]) == valueJson).map(u => update)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
}
|
|
40
67
|
}
|
|
41
68
|
this.observer = (signal, ...args) => {
|
|
42
|
-
if
|
|
43
|
-
if
|
|
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)
|
package/package.json
CHANGED
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"url": "https://github.com/live-change/live-change-dao.git"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"debug": "^4.
|
|
16
|
+
"debug": "^4.3.2"
|
|
17
17
|
},
|
|
18
18
|
"description": "live data access object",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"blue-tape": "^1.0.0",
|
|
21
|
-
"supports-color": "^
|
|
21
|
+
"supports-color": "^7.2.0"
|
|
22
22
|
},
|
|
23
23
|
"directories": {},
|
|
24
24
|
"license": "MIT",
|
|
@@ -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.4",
|
|
39
|
+
"gitHead": "9ddc0d69695d818a2b3a57bf0ff36a2b36133ea4"
|
|
40
40
|
}
|