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>
29 lines
1.2 KiB
Text
29 lines
1.2 KiB
Text
# ui_reload.ludic — a template read from disk, changed there, and read again by ui_reload: the new
|
|
# text shows at once, and the screen's state (a counter pressed before the change) is kept.
|
|
import "ludic.ui"
|
|
program UiReload {
|
|
numbers float
|
|
view Note {
|
|
title = "note"
|
|
}
|
|
const PATH: string = "build/ui_reload_example.xml"
|
|
const V1: string = "<ui><screen name='note'><state n='{0}'/><button on-click='set n = n + 1'>{title} {n}</button></screen></ui>"
|
|
const V2: string = "<ui><screen name='note'><state n='{0}'/><h1>{title} again {n}</h1></screen></ui>"
|
|
function shown(ui_st: mut UiState) -> string {
|
|
let root: UiNode = ui_nodes(ui_st, "note", view_note())
|
|
let first = root.children[0]
|
|
if len(first.children) > 0 { return first.children[0].text }
|
|
return first.text
|
|
}
|
|
entry (ui_st: mut UiState) {
|
|
Fs.write_text(PATH, V1)
|
|
ui_load(ui_st, PATH)
|
|
let root: UiNode = ui_nodes(ui_st, "note", view_note())
|
|
ui_press(ui_st, root.children[0])
|
|
let before = shown(ui_st)
|
|
let same = ui_reload(ui_st)
|
|
Fs.write_text(PATH, V2)
|
|
let changed = ui_reload(ui_st)
|
|
print(`{before} | reloaded {same} then {changed} | {shown(ui_st)}`)
|
|
}
|
|
}
|