Skip to main content

create_migration_map

Function create_migration_map 

Source
pub fn create_migration_map(
    node_moves: &[NodeMove],
) -> FastHashMap<NodeId, NodeId>
Expand description

Migrate state (focus, scroll, etc.) from old node IDs to new node IDs.

This function should be called after reconciliation to update any state that references old NodeIds to use the new NodeIds.

ยงExample

let diff = reconcile_dom(...);
let migration_map = create_migration_map(&diff.node_moves);
 
// Migrate focus
if let Some(current_focus) = focus_manager.focused_node {
    if let Some(&new_id) = migration_map.get(&current_focus) {
        focus_manager.focused_node = Some(new_id);
    } else {
        // Focused node was unmounted, clear focus
        focus_manager.focused_node = None;
    }
}