Add, remove, and filter
Dynamic lists have two classic pitfalls: unbounded heap growth on embedded targets, and index-based keys that delete or scramble the wrong row when items are filtered.
1. Minimal demo: ModelList, TextInput, and walk
ModelList::bounded(N) provides a fixed-capacity reactive collection and assigns each item a stable ModelItemId.
In this minimal demo, TextInput binds a TextDocument draft, tapping + Add (or pressing Return) pushes a new item, and walk ${ notes.items().entries() } with entry by entry.0 keys each row by its ModelItemId:
2. In the task list: adding, removing, and filtering tasks
Now we wire TextInput, Remove buttons, and the All / Open / Done filter bar into the task list.
Inspect the focused changes across model.rs and interface.rs (marked with +): filtering never removes items from ModelList—it simply binds each row's visible property to tasks.filter().includes(task.done()), while the header tally continues to report the full list:
While typing in `TextInput`, keystrokes mutate the isolated `draft: TextDocument` model—the task list itself is not touched or re-laid out on every keystroke.
TextInput(...) [TextEditing::new(draft.clone()), Placeholder("New task")]Decouples IME/caret churn from business listWhat changed in this step
- Addressing by
ModelItemIdinstead of index: When completed rows are hidden underOpen, the first visible row on screen may be the second item in storage. PassingModelItemIdtoEdit::Remove(key)ensures deletion always hits the exact item you tapped. - Decoupled text draft: Cursor movement and text selection live inside
TextDocument.Tasksis only mutated whenedit_tasksfires on Return or+ Add.
Run on your machine
cargo run -p mirui-first-app --features desktop --example desktop -- 3