jails-js 6.5.4 → 6.6.0
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/dist/index.js +35 -16
- package/dist/index.js.map +1 -1
- package/dist/jails.js +1 -1
- package/dist/jails.js.map +1 -1
- package/package.json +1 -1
- package/src/component.ts +20 -1
- package/src/utils/index.ts +2 -1
- package/types.d.ts +2 -0
package/src/component.ts
CHANGED
@@ -8,6 +8,7 @@ export const Component = ({ name, module, dependencies, node, templates, signal,
|
|
8
8
|
let preserve = []
|
9
9
|
let observer = null
|
10
10
|
let observables = []
|
11
|
+
let effect = null
|
11
12
|
|
12
13
|
const _model = module.model || {}
|
13
14
|
const initialState = (new Function( `return ${node.getAttribute('html-model') || '{}'}`))()
|
@@ -32,6 +33,14 @@ export const Component = ({ name, module, dependencies, node, templates, signal,
|
|
32
33
|
node.addEventListener(':mount', fn)
|
33
34
|
},
|
34
35
|
|
36
|
+
effect(fn) {
|
37
|
+
if( fn ) {
|
38
|
+
effect = fn
|
39
|
+
} else {
|
40
|
+
return effect
|
41
|
+
}
|
42
|
+
},
|
43
|
+
|
35
44
|
/**
|
36
45
|
* @State
|
37
46
|
*/
|
@@ -220,7 +229,17 @@ export const Component = ({ name, module, dependencies, node, templates, signal,
|
|
220
229
|
const child = register.get(element)
|
221
230
|
if(!child) return
|
222
231
|
child.state.protected().forEach( key => delete data[key] )
|
223
|
-
child.
|
232
|
+
const useEffect = child.effect()
|
233
|
+
if( useEffect ) {
|
234
|
+
const promise = useEffect(data)
|
235
|
+
if( promise && promise.then ) {
|
236
|
+
promise.then(() => child.state.set(data))
|
237
|
+
} else {
|
238
|
+
child.state.set(data)
|
239
|
+
}
|
240
|
+
} else {
|
241
|
+
child.state.set(data)
|
242
|
+
}
|
224
243
|
})
|
225
244
|
Promise.resolve().then(() => {
|
226
245
|
g.scope = {}
|
package/src/utils/index.ts
CHANGED