@pyreon/core 0.1.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/src/types.ts ADDED
@@ -0,0 +1,61 @@
1
+ // ─── VNode ────────────────────────────────────────────────────────────────────
2
+
3
+ // Reactive getter returning a child — wraps dynamic expressions in `() =>`
4
+ export type VNodeChildAtom = VNode | VNode[] | string | number | boolean | null | undefined
5
+ export type VNodeChild = VNodeChildAtom | (() => VNodeChildAtom)
6
+
7
+ export interface VNode {
8
+ /** Tag name, component function, or special symbol (Fragment) */
9
+ type: string | ComponentFn | symbol
10
+ props: Props
11
+ children: VNodeChild[]
12
+ key: string | number | null
13
+ }
14
+
15
+ // ─── Props ────────────────────────────────────────────────────────────────────
16
+
17
+ export type Props = Record<string, unknown>
18
+
19
+ // ─── Component ────────────────────────────────────────────────────────────────
20
+
21
+ /**
22
+ * A component is a plain function that runs ONCE.
23
+ * It returns a VNode (or null) and may call lifecycle hooks during setup.
24
+ */
25
+ export type ComponentFn<P extends Props = Props> = (props: P) => VNode | null
26
+
27
+ /**
28
+ * Internal runtime handle created by the renderer for each mounted component.
29
+ */
30
+ export interface ComponentInstance {
31
+ vnode: VNode | null
32
+ /** Trigger a re-check / patch cycle (called by the renderer) */
33
+ update(): void
34
+ unmount(): void
35
+ }
36
+
37
+ // ─── Lifecycle hooks storage (attached per-instance by the renderer) ──────────
38
+
39
+ // Cleanup function optionally returned by onMount hooks
40
+ export type CleanupFn = () => void
41
+
42
+ // ─── NativeItem ───────────────────────────────────────────────────────────────
43
+
44
+ /**
45
+ * Result of createTemplate() — a pre-cloned DOM element with its cleanup.
46
+ * Handled directly by mountFor without going through the VNode reconciler,
47
+ * saving 2 allocations per row vs the VNode wrapper path.
48
+ */
49
+ export interface NativeItem {
50
+ readonly __isNative: true
51
+ el: HTMLElement
52
+ cleanup: (() => void) | null
53
+ }
54
+
55
+ export interface LifecycleHooks {
56
+ mount: (() => CleanupFn | undefined)[]
57
+ unmount: (() => void)[]
58
+ update: (() => void)[]
59
+ /** Error handlers — return true to mark the error as handled (stops propagation). */
60
+ error: ((err: unknown) => boolean | undefined)[]
61
+ }