docs: add notes about apply diff

This commit is contained in:
Zixuan Chen 2024-08-08 18:27:49 +08:00
parent 2b6dae8393
commit 868ee2e8cc
No known key found for this signature in database
2 changed files with 8 additions and 0 deletions

View file

@ -960,6 +960,8 @@ impl ContainerState for MovableListState {
self.list().is_empty() && self.elements().is_empty()
}
// How we apply the diff is coupled with the [DiffMode] we used to calculate the diff.
// So be careful when you modify this function.
#[instrument(skip_all)]
fn apply_diff_and_convert(
&mut self,
@ -1237,6 +1239,8 @@ impl ContainerState for MovableListState {
Diff::List(event)
}
// How we apply the diff is coupled with the [DiffMode] we used to calculate the diff.
// So be careful when you modify this function.
fn apply_diff(&mut self, diff: InternalDiff, ctx: DiffApplyContext) {
let _ = self.apply_diff_and_convert(diff, ctx);
}

View file

@ -852,6 +852,8 @@ impl ContainerState for TreeState {
self.nodes().is_empty()
}
// How we apply the diff is coupled with the [DiffMode] we used to calculate the diff.
// So be careful when you modify this function.
fn apply_diff_and_convert(
&mut self,
diff: crate::event::InternalDiff,
@ -972,6 +974,8 @@ impl ContainerState for TreeState {
Diff::Tree(TreeDiff { diff: ans })
}
// How we apply the diff is coupled with the [DiffMode] we used to calculate the diff.
// So be careful when you modify this function.
fn apply_diff(&mut self, diff: InternalDiff, ctx: DiffApplyContext) {
if let InternalDiff::Tree(tree) = &diff {
let need_check = !matches!(ctx.mode, DiffMode::Checkout | DiffMode::Linear);