Skip to main content

transfer_states

Function transfer_states 

Source
pub fn transfer_states(
    old_node_data: &mut [NodeData],
    new_node_data: &mut [NodeData],
    node_moves: &[NodeMove],
)
Expand description

Executes state migration between the old DOM and the new DOM based on diff results.

This iterates through matched nodes. If a match has BOTH a merge callback AND a dataset, it executes the callback to transfer state from the old node to the new node.

This must be called before the old DOM is dropped, because we need to access its data.

§Arguments

  • old_node_data - Mutable reference to the old DOM’s node data (source of heavy state)
  • new_node_data - Mutable reference to the new DOM’s node data (target for heavy state)
  • node_moves - The matched nodes from the reconciliation diff

§Example

let diff_result = reconcile_dom(&old_data, &new_data, ...);
 
// Execute state migration BEFORE old_dom is dropped
transfer_states(&mut old_data, &mut new_data, &diff_result.node_moves);
 
// Now safe to drop old_dom - heavy resources have been transferred
drop(old_dom);