@snupo/jmc 1.1.0 → 1.3.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/design-guide.md +193 -0
- package/dist/base.d.ts +6 -1
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +8 -1
- package/dist/base.js.map +1 -1
- package/dist/jmc.d.ts.map +1 -1
- package/dist/jmc.js +10 -4
- package/dist/jmc.js.map +1 -1
- package/dist/jsx.d.ts +56 -75
- package/dist/jsx.d.ts.map +1 -1
- package/dist/jsx.js +0 -19
- package/dist/jsx.js.map +1 -1
- package/dist/props.d.ts.map +1 -1
- package/dist/props.js +11 -2
- package/dist/props.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +16 -2
- package/src/base.ts +6 -1
- package/src/jmc.ts +11 -2
- package/src/jsx.ts +1386 -1390
- package/src/props.ts +9 -2
- package/dist/events.d.ts +0 -9
- package/dist/events.d.ts.map +0 -1
- package/dist/events.js +0 -17
- package/dist/events.js.map +0 -1
- package/src/events.ts +0 -25
package/src/base.ts
CHANGED
|
@@ -23,6 +23,11 @@ export const loggedmethods = <T extends Record<string, any>>(o: T): T => loggedm
|
|
|
23
23
|
|
|
24
24
|
export function closestby(e: Node | null, pred: (e: Node) => boolean): Node | null { return (e == null || pred(e)) ? e : closestby(e.parentNode, pred) }
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/** a prop value evaluated at each render */
|
|
27
|
+
export class Thunk<T> {
|
|
28
|
+
constructor(public f: () => T) { }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function lazy<T>(f: () => T) { return new Thunk(f) }
|
|
27
32
|
|
|
28
33
|
export function mount(o: Record<string, any>) { Object.assign(globalThis, o) }
|
package/src/jmc.ts
CHANGED
|
@@ -25,6 +25,9 @@ type JNode<N extends Node = ChildNode> = N & {
|
|
|
25
25
|
ep?: J
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/** mounted callbacks collected by sync, run after it in the lifecycle phase. children before their parents */
|
|
29
|
+
let mounts: (() => void)[] = []
|
|
30
|
+
|
|
28
31
|
let removeexcesschildren = (n: Element, i: number) => {
|
|
29
32
|
let c: ChildNode
|
|
30
33
|
while ((c = n.childNodes[i])) {
|
|
@@ -106,7 +109,7 @@ function sync(
|
|
|
106
109
|
removeexcesschildren(n, j)
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
|
-
if (fresh) p.mounted
|
|
112
|
+
if (fresh && p.mounted) mounts.push(() => p.mounted(n))
|
|
110
113
|
|
|
111
114
|
return i + 1
|
|
112
115
|
}
|
|
@@ -130,7 +133,7 @@ function sync(
|
|
|
130
133
|
let j = sync(parent, i, hv, old ?? h, depth, uc) // the attached H, so updates find the instance
|
|
131
134
|
assertnonfragment(h, hv, i, j)
|
|
132
135
|
ci.element = parent.childNodes[i]
|
|
133
|
-
if (!old) ci.mounted
|
|
136
|
+
if (!old && ci.mounted) mounts.push(() => ci.mounted!())
|
|
134
137
|
return j
|
|
135
138
|
}
|
|
136
139
|
|
|
@@ -166,6 +169,12 @@ export function patch(
|
|
|
166
169
|
let p = e.parentElement!
|
|
167
170
|
let i = [...p.childNodes].indexOf(e as ChildNode)
|
|
168
171
|
sync(p, i, h, undefined, depth, uc)
|
|
172
|
+
|
|
173
|
+
// lifecycle phase: the dom is complete now. taken first, a mounted callback calling updateview collects anew
|
|
174
|
+
let ms = mounts
|
|
175
|
+
mounts = []
|
|
176
|
+
ms.forEach(m => m())
|
|
177
|
+
|
|
169
178
|
return p.childNodes[i] as HTMLElement
|
|
170
179
|
}
|
|
171
180
|
|