@kudzujs/core 0.3.0 → 0.4.1
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/README.md +56 -12
- package/framework/README.md +4 -3
- package/framework/binding-runtime.js +41 -22
- package/framework/build.mjs +254 -13
- package/framework/core.d.ts +7 -1
- package/framework/core.mjs +182 -30
- package/framework/list-runtime.js +233 -0
- package/framework/native-runtime.js +31 -12
- package/framework/shared-runtime.js +19 -0
- package/package.json +1 -1
|
@@ -16,11 +16,21 @@ export function applyCommands(state, commands, commit, log = console.log) {
|
|
|
16
16
|
|
|
17
17
|
export const browserState = new Map()
|
|
18
18
|
const committers = []
|
|
19
|
+
const mountHooks = []
|
|
20
|
+
const unmountHooks = []
|
|
19
21
|
|
|
20
22
|
export function registerCommitter(commit) {
|
|
21
23
|
committers.push(commit)
|
|
22
24
|
}
|
|
23
25
|
|
|
26
|
+
export function registerMountHook(mount) {
|
|
27
|
+
mountHooks.push(mount)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function registerUnmountHook(unmount) {
|
|
31
|
+
unmountHooks.push(unmount)
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
export function commitDom(id, value) {
|
|
25
35
|
for (const node of document.querySelectorAll(`[data-k-text="${id}"]`)) node.textContent = value
|
|
26
36
|
for (const commit of committers) commit(id)
|
|
@@ -34,6 +44,15 @@ export function mountText(root) {
|
|
|
34
44
|
}
|
|
35
45
|
}
|
|
36
46
|
|
|
47
|
+
export function mountDom(root) {
|
|
48
|
+
mountText(root)
|
|
49
|
+
for (const mount of mountHooks) mount(root)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function unmountDom(root) {
|
|
53
|
+
for (const unmount of unmountHooks) unmount(root)
|
|
54
|
+
}
|
|
55
|
+
|
|
37
56
|
if (typeof document !== "undefined") {
|
|
38
57
|
const initialState = document.body.dataset.kState
|
|
39
58
|
if (initialState) for (const [id, value] of JSON.parse(initialState)) browserState.set(id, value)
|