# life.ludic - on-mount and on-unmount: an element or component that appears in a frame it was not # in last frame is mounted, and one that is gone is unmounted, each once, after the frame is drawn # a build starts its own records: a screen built twice keeps only the last build's function lc_begin(ui_st: mut UiState) -> void { List.clear(ui_st.lc_keys) List.clear(ui_st.lc_mounts) List.clear(ui_st.lc_unmounts) List.clear(ui_st.lc_envs) } function lc_note(ui_st: mut UiState, key: string, names: []string, acts: []UiAct, e: UiEnv) -> void { var m: UiAct = null var u: UiAct = null for i in 0 .. len(names) { if names[i] == "mount" { m = acts[i] } if names[i] == "unmount" { u = acts[i] } } if m == null and u == null { return } ui_kept(ui_st.lc_keys, key) ui_kept(ui_st.lc_mounts, m) ui_kept(ui_st.lc_unmounts, u) ui_kept(ui_st.lc_envs, e) } function lc_mine(key: string, screen: string) -> bool { let n = len(screen) return key == screen or (len(key) > n and sat(key, 0, screen) and key[n] == 47) } # the screen's mounts and unmounts since its last frame; other screens' records are kept function lc_run(ui_st: mut UiState, screen: string) -> void { for i in 0 .. len(ui_st.lc_keys) { if ui_st.lc_mounts[i] != null and not sel_has(ui_st.lc_prev_keys, ui_st.lc_keys[i]) { act_run(ui_st, ui_st.lc_mounts[i], ui_st.lc_envs[i]) } } let keys = ui_st.lc_sp_keys # the spare set, emptied: the records carried over let unmounts = ui_st.lc_sp_unmounts let envs = ui_st.lc_sp_envs List.clear(keys) List.clear(unmounts) List.clear(envs) for i in 0 .. len(ui_st.lc_prev_keys) { let k = ui_st.lc_prev_keys[i] if lc_mine(k, screen) { if ui_st.lc_prev_unmounts[i] != null and not sel_has(ui_st.lc_keys, k) { act_run(ui_st, ui_st.lc_prev_unmounts[i], ui_st.lc_prev_envs[i]) } } else { ui_kept(keys, k) ui_kept(unmounts, ui_st.lc_prev_unmounts[i]) ui_kept(envs, ui_st.lc_prev_envs[i]) } } for i in 0 .. len(ui_st.lc_keys) { ui_kept(keys, ui_st.lc_keys[i]) ui_kept(unmounts, ui_st.lc_unmounts[i]) ui_kept(envs, ui_st.lc_envs[i]) } ui_st.lc_sp_keys = ui_st.lc_prev_keys ui_st.lc_sp_unmounts = ui_st.lc_prev_unmounts ui_st.lc_sp_envs = ui_st.lc_prev_envs ui_st.lc_prev_keys = keys ui_st.lc_prev_unmounts = unmounts ui_st.lc_prev_envs = envs List.clear(ui_st.lc_keys) List.clear(ui_st.lc_mounts) List.clear(ui_st.lc_unmounts) List.clear(ui_st.lc_envs) }