pub fn reconcile_children(
old: &[ReconcileInputChild],
new_keys: &[Option<Key>],
) -> Vec<Option<ReconcileOutputChild>>Expand description
Reconciles children by index when no keys exist, otherwise by stable key.
- If
new_keys[i]isSome(k), reuse the old child with the same key when present. - Otherwise try reuse by index when possible.
- Unmatched slots return
Nonefor the caller to create new elements.
Key lookup is built from the old slice in order, so duplicate old keys use the last matching ID. Duplicate new keys may select the same old ID more than once. An unkeyed new slot can positionally reuse an old keyed child. This helper does not enforce uniqueness or mutate either input.
ยงExamples
use ailloli_ui_core::ElementId;
use ailloli_ui_runtime::element::{reconcile_children, Key, ReconcileInputChild};
let old = [
ReconcileInputChild { id: ElementId(1), key: Some(Key::Static("a")) },
ReconcileInputChild { id: ElementId(2), key: Some(Key::Static("b")) },
];
let result = reconcile_children(&old, &[Some(Key::Static("b")), None, None]);
assert_eq!(result[0].as_ref().unwrap().id, ElementId(2));
assert_eq!(result[1].as_ref().unwrap().id, ElementId(2));
assert!(result[2].is_none());