ludic.ui: an unmounted component is mounted again rather than made again - its record renewed (a generated renew), its props and model kept; an action's call answers into a ring

A prompt that comes and goes as a player walks (co-op's netleak: in_get, cmp_*_new, bd_class, value_slot/put)
made a new record, props and model on every mount, and an action's call answered into a new Val (ev_call_with).
examples/library/ui_remount: two thousand comings and goings hold the heap at 0, and the counter starts at 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 15:25:55 +03:00
parent fc0f3d3790
commit 6cdef20cc2
14 changed files with 46052 additions and 45244 deletions

View file

@ -0,0 +1,30 @@
# ui_remount.ludic - a component that comes and goes: mounted again, it starts as new (its state back
# to its defaults), and a thousand comings and goings hold the heap flat, because an unmounted
# instance is put back and mounted again rather than a record, props and model made each time
import "ludic.ui"
import "ui_remount_parts/Counter.ludic"
import "ui_remount_parts/Shown.ludic"
program UiRemount {
numbers float
function frame(ui_st: mut UiState) -> UiNode {
let root: UiNode = ui_nodes(ui_st, "Shown", null)
ui_place(ui_st, root, 0.0, 0.0, 300.0, 200.0)
return root
}
entry (ui_st: mut UiState) {
var root = frame(ui_st)
let c = root.children[0].children[1]
ui_press(ui_st, c.children[1])
ui_press(ui_st, c.children[1])
root = frame(ui_st)
let before = root.children[0].children[1].children[0].text
var at = 0
for i in 0 .. 2000 {
ui_press(ui_st, root.children[0].children[0])
root = frame(ui_st)
if i == 99 { at = Os.heap_bytes() }
}
let grew = Os.heap_bytes() - at
print(`{before} | {root.children[0].children[1].children[0].text} | heap {grew}`)
}
}

View file

@ -0,0 +1,9 @@
# Counter.ludic - a counter that starts at 0 each time it is mounted
component Counter {
prop label: string
prop step: int = 1
state count: int = 0
doubled: int = count * 2
function big() -> bool { return count > 3 }
on bump() { count += step }
}

View file

@ -0,0 +1,5 @@
<div class="counter">
<p>{label}: {count} ({doubled}){big() ? ' big' : ''}</p>
<button on-click="bump()">+</button>
<button on-click="set count = 0">reset</button>
</div>

View file

@ -0,0 +1,5 @@
# Shown.ludic - a counter shown or not: each time it comes back it is a new counter
component Shown {
state on: bool = true
on flip() { on = not on }
}

View file

@ -0,0 +1,4 @@
<div>
<button on-click="flip()">flip</button>
<if test="{on}"><Counter label="c"/></if>
</div>