ludic/packages/ludic.ui/instance.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

33 lines
1,017 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
}
function in_get(ui_st: mut UiState, key: string, k: UiClass) -> UiInst {
for i in 0 .. len(ui_st.in_list) {
let it = ui_st.in_list[i]
if it.key == key and it.cls.name == k.name {
it.seen = ui_st.in_build
return it
}
}
let it = new UiInst
it.key = key
it.cls = k
it.ptr = k.make()
it.seen = ui_st.in_build
push(ui_st.in_list, it)
return it
}
# after a build of `screen`: its instances the build did not reach are unmounted
function in_sweep(ui_st: mut UiState, screen: string) -> void {
let keep = new []UiInst
for i in 0 .. len(ui_st.in_list) {
let it = ui_st.in_list[i]
if it.seen == ui_st.in_build or not lc_mine(it.key, screen) { push(keep, it) }
}
ui_st.in_list = keep
}