@live-change/dao-vue3 0.4.8 → 0.4.11
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/live.js +43 -21
- package/package.json +3 -3
package/lib/live.js
CHANGED
|
@@ -6,6 +6,24 @@ debug.log = console.log.bind(console)
|
|
|
6
6
|
|
|
7
7
|
const liveSymbol = Symbol('live')
|
|
8
8
|
|
|
9
|
+
function createActionFunction(action, object) {
|
|
10
|
+
function getSource(ptr) {
|
|
11
|
+
throw new Error('not implemented')
|
|
12
|
+
/// TODO: implement
|
|
13
|
+
}
|
|
14
|
+
const objectParams = () => {
|
|
15
|
+
const params = collectPointers(object, [action.params], getSource)[0]
|
|
16
|
+
return params
|
|
17
|
+
}
|
|
18
|
+
const func = async (additionalParams) => {
|
|
19
|
+
const params = { ...additionalParams, ...objectParams() }
|
|
20
|
+
return api.request(action.path, params)
|
|
21
|
+
}
|
|
22
|
+
func.params = objectParams
|
|
23
|
+
func.path = action.path
|
|
24
|
+
return func
|
|
25
|
+
}
|
|
26
|
+
|
|
9
27
|
async function live(api, path, onUnmountedCb) {
|
|
10
28
|
if(isRef(path)) {
|
|
11
29
|
/// TODO: support path as ref/computed
|
|
@@ -72,17 +90,18 @@ async function live(api, path, onUnmountedCb) {
|
|
|
72
90
|
return createObject(path.what, path.more)
|
|
73
91
|
} else {
|
|
74
92
|
const preFetchPaths = api.observable({ paths })
|
|
75
|
-
function bindResult(what, more, object, property, onError) {
|
|
93
|
+
function bindResult(what, more, actions, object, property, onError) {
|
|
76
94
|
if(!what) throw new Error("what parameter required!")
|
|
77
95
|
const observable = api.observable(what)
|
|
78
96
|
const errorObserver = { error: onError }
|
|
79
|
-
|
|
97
|
+
let dispose
|
|
98
|
+
if((more && more.some(m => m.to)) || actions) {
|
|
80
99
|
const extendedObservable = new ExtendedObservableList(observable,
|
|
81
100
|
newElement => {
|
|
82
101
|
if(!newElement) return newElement
|
|
83
102
|
const extendedElement = reactive({ ...newElement })
|
|
84
103
|
const props = {}
|
|
85
|
-
for(const moreElement of more) {
|
|
104
|
+
if(more) for(const moreElement of more) {
|
|
86
105
|
if(moreElement.to) {
|
|
87
106
|
const prop = {
|
|
88
107
|
bounds: [],
|
|
@@ -118,7 +137,8 @@ async function live(api, path, onUnmountedCb) {
|
|
|
118
137
|
const newArray = new Array(pointers.length)
|
|
119
138
|
const newBounds = new Array(pointers.length)
|
|
120
139
|
for(let i = 0; i < pointers.length; i++) {
|
|
121
|
-
newBounds[i] = bindResult(pointers[i],
|
|
140
|
+
newBounds[i] = bindResult(pointers[i], moreElement.more, moreElement.actions,
|
|
141
|
+
newArray, i, onError)
|
|
122
142
|
}
|
|
123
143
|
prop.bounds = newBounds
|
|
124
144
|
oldBound.forEach(b => b.dispose())
|
|
@@ -132,7 +152,8 @@ async function live(api, path, onUnmountedCb) {
|
|
|
132
152
|
}
|
|
133
153
|
if(pointers[0]) {
|
|
134
154
|
prop.bounds = [
|
|
135
|
-
bindResult(pointers[0], moreElement.more,
|
|
155
|
+
bindResult(pointers[0], moreElement.more, moreElement.actions,
|
|
156
|
+
extendedElement, moreElement.to, onError)
|
|
136
157
|
]
|
|
137
158
|
}
|
|
138
159
|
}
|
|
@@ -141,6 +162,11 @@ async function live(api, path, onUnmountedCb) {
|
|
|
141
162
|
bindPointers(computePointers())
|
|
142
163
|
}
|
|
143
164
|
}
|
|
165
|
+
if(actions) for(const action of actions) {
|
|
166
|
+
if(!action.name) continue
|
|
167
|
+
debug("BIND ACTION", action.name, "TO", object)
|
|
168
|
+
extendedElement[action.name] = createActionFunction(action, extendedElement)
|
|
169
|
+
}
|
|
144
170
|
extendedElement[liveSymbol] = props
|
|
145
171
|
return extendedElement
|
|
146
172
|
},
|
|
@@ -172,27 +198,23 @@ async function live(api, path, onUnmountedCb) {
|
|
|
172
198
|
)
|
|
173
199
|
extendedObservable.bindProperty(object, property)
|
|
174
200
|
observable.observe(errorObserver)
|
|
175
|
-
|
|
176
|
-
what,
|
|
177
|
-
property
|
|
178
|
-
|
|
179
|
-
debug("UNBIND PROPERTY", what, object, property)
|
|
180
|
-
extendedObservable.unbindProperty(object, property)
|
|
181
|
-
observable.unobserve(errorObserver)
|
|
182
|
-
}
|
|
201
|
+
dispose = () => {
|
|
202
|
+
debug("UNBIND PROPERTY", what, object, property)
|
|
203
|
+
extendedObservable.unbindProperty(object, property)
|
|
204
|
+
observable.unobserve(errorObserver)
|
|
183
205
|
}
|
|
184
206
|
} else {
|
|
185
207
|
observable.bindProperty(object, property)
|
|
186
208
|
observable.observe(errorObserver)
|
|
187
|
-
|
|
188
|
-
what, property
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
observable.unbindProperty(object, property)
|
|
192
|
-
observable.unobserve(errorObserver)
|
|
193
|
-
}
|
|
209
|
+
dispose = () => {
|
|
210
|
+
debug("UNBIND PROPERTY", what, object, property)
|
|
211
|
+
observable.unbindProperty(object, property)
|
|
212
|
+
observable.unobserve(errorObserver)
|
|
194
213
|
}
|
|
195
214
|
}
|
|
215
|
+
return {
|
|
216
|
+
what, property, dispose
|
|
217
|
+
}
|
|
196
218
|
}
|
|
197
219
|
const resultRef = ref()
|
|
198
220
|
await new Promise((resolve, reject) => {
|
|
@@ -203,7 +225,7 @@ async function live(api, path, onUnmountedCb) {
|
|
|
203
225
|
error = msg
|
|
204
226
|
reject(error)
|
|
205
227
|
}
|
|
206
|
-
const bound = bindResult(path.what, path.more, resultRef, 'value', onError)
|
|
228
|
+
const bound = bindResult(path.what, path.more, path.actions, resultRef, 'value', onError)
|
|
207
229
|
const pathsObserver = (signal, value) => {}
|
|
208
230
|
preFetchPaths.observe(pathsObserver)
|
|
209
231
|
onUnmountedCb(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/dao-vue3",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"author": {
|
|
5
5
|
"email": "m8@em8.pl",
|
|
6
6
|
"name": "Michał Łaszczewski",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "https://github.com/live-change/live-change-dao/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@live-change/dao": "^0.4.
|
|
13
|
+
"@live-change/dao": "^0.4.10"
|
|
14
14
|
},
|
|
15
15
|
"description": "Vue.js integration for live-change dao",
|
|
16
16
|
"directories": {},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"compileTests": "webpack test/*.js tests-bundle.js"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "dce5205dd62478b96648556e865959f51f4ca737"
|
|
36
36
|
}
|