The compiler turns a component declaration into: - a record of its props and state; - a constructor, a props setter, a model and a call; - a class, registered with ludic.ui at start. Its template and styles are read from beside it and compiled in, with @import inlined, and a missing template fails the build. In the runtime: - each mounted instance keeps its own props and state, and `set` in a template writes the state; - styles are scoped to the component; - class, style and id on a component's tag land on its root, styled by the parent's sheet too; - ui_reload re-reads a component's files from disk and keeps instances. The package's own module is now ludic_ui, so a program may call a directory of its own ui. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
35 lines
982 B
Text
35 lines
982 B
Text
# instance.ludic - a mounted component's record (its props and state), found by where it sits in the
|
|
# tree; one that a build of its screen did not reach is gone, and its state with it
|
|
property UiInst {
|
|
key: string = ""
|
|
cls: UiClass = null
|
|
ptr: pointer = null
|
|
seen: int = 0
|
|
}
|
|
var in_list: []UiInst = new []UiInst
|
|
var in_build: int = 0
|
|
function in_get(key: string, k: UiClass) -> UiInst {
|
|
for i in 0 .. len(in_list) {
|
|
let it = in_list[i]
|
|
if it.key == key and it.cls.name == k.name {
|
|
it.seen = in_build
|
|
return it
|
|
}
|
|
}
|
|
let it = new UiInst
|
|
it.key = key
|
|
it.cls = k
|
|
it.ptr = k.make()
|
|
it.seen = in_build
|
|
push(in_list, it)
|
|
return it
|
|
}
|
|
# after a build of `screen`: its instances the build did not reach are unmounted
|
|
function in_sweep(screen: string) -> void {
|
|
let keep = new []UiInst
|
|
for i in 0 .. len(in_list) {
|
|
let it = in_list[i]
|
|
if it.seen == in_build or not lc_mine(it.key, screen) { push(keep, it) }
|
|
}
|
|
in_list = keep
|
|
}
|