(&mut self, changes: InternalChanges, handler: &mut impl ChangeHandler)
| 643 | } |
| 644 | |
| 645 | fn process_changes(&mut self, changes: InternalChanges, handler: &mut impl ChangeHandler) { |
| 646 | for id in &changes.added_node_ids { |
| 647 | let node = self.next_state.node_by_id(*id).unwrap(); |
| 648 | handler.node_added(&node); |
| 649 | } |
| 650 | for id in &changes.updated_node_ids { |
| 651 | let old_node = self.state.node_by_id(*id).unwrap(); |
| 652 | let new_node = self.next_state.node_by_id(*id).unwrap(); |
| 653 | handler.node_updated(&old_node, &new_node); |
| 654 | } |
| 655 | let old_focus = self.state.focus(); |
| 656 | let new_focus = self.next_state.focus(); |
| 657 | if old_focus.as_ref().map(|n| n.id()) != new_focus.as_ref().map(|n| n.id()) { |
| 658 | if let Some(old_node) = &old_focus { |
| 659 | let id = old_node.id(); |
| 660 | if !changes.updated_node_ids.contains(&id) |
| 661 | && !changes.removed_node_ids.contains(&id) |
| 662 | { |
| 663 | if let Some(old_node_new_version) = self.next_state.node_by_id(id) { |
| 664 | handler.node_updated(old_node, &old_node_new_version); |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | if let Some(new_node) = &new_focus { |
| 669 | let id = new_node.id(); |
| 670 | if !changes.added_node_ids.contains(&id) && !changes.updated_node_ids.contains(&id) |
| 671 | { |
| 672 | if let Some(new_node_old_version) = self.state.node_by_id(id) { |
| 673 | handler.node_updated(&new_node_old_version, new_node); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | handler.focus_moved(old_focus.as_ref(), new_focus.as_ref()); |
| 678 | } |
| 679 | for id in &changes.removed_node_ids { |
| 680 | let node = self.state.node_by_id(*id).unwrap(); |
| 681 | handler.node_removed(&node); |
| 682 | } |
| 683 | for id in changes.added_node_ids { |
| 684 | self.state |
| 685 | .nodes |
| 686 | .insert(id, self.next_state.nodes.get(&id).unwrap().clone()); |
| 687 | } |
| 688 | for id in changes.updated_node_ids { |
| 689 | self.state |
| 690 | .nodes |
| 691 | .get_mut(&id) |
| 692 | .unwrap() |
| 693 | .clone_from(self.next_state.nodes.get(&id).unwrap()); |
| 694 | } |
| 695 | for id in changes.removed_node_ids { |
| 696 | self.state.nodes.remove(&id); |
| 697 | } |
| 698 | if self.state.data != self.next_state.data { |
| 699 | self.state.data.clone_from(&self.next_state.data); |
| 700 | } |
| 701 | self.state.root = self.next_state.root; |
| 702 | self.state.focus = self.next_state.focus; |
no test coverage detected