Skip to content

Commit e2a664a

Browse files
committed
fix: SyncedCollection
1 parent 3cd3218 commit e2a664a

File tree

8 files changed

+1471
-1565
lines changed

8 files changed

+1471
-1565
lines changed

packages/frender/src/elements/synced_collection.rs

Lines changed: 8 additions & 1565 deletions
Large diffs are not rendered by default.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
pub(super) enum MountState {
2+
MountedAndUpToDate,
3+
MountedAndUpToDateButPreviousWasSkipped,
4+
Outdated,
5+
OutdatedAndPreviousWasSkipped,
6+
OutdatedAndMoved,
7+
// UpdateToDateButMoved,
8+
}
9+
10+
impl MountState {
11+
// caller should mark the next one as previous_was_skipped
12+
// There might be a UpdateToDateButMoved variant so this method is different from mark_as_outdated_and_moved
13+
pub(crate) fn mark_as_moved(&mut self) {
14+
*self = Self::OutdatedAndMoved
15+
}
16+
17+
// caller should mark the next one as previous_was_skipped
18+
pub(crate) fn mark_as_outdated_and_moved(&mut self) {
19+
*self = Self::OutdatedAndMoved
20+
}
21+
22+
pub(crate) fn mark_as_outdated(&mut self) {
23+
*self = match self {
24+
MountState::MountedAndUpToDate => Self::Outdated,
25+
MountState::Outdated => Self::Outdated,
26+
MountState::OutdatedAndMoved => MountState::OutdatedAndMoved,
27+
MountState::MountedAndUpToDateButPreviousWasSkipped => {
28+
MountState::OutdatedAndPreviousWasSkipped
29+
}
30+
MountState::OutdatedAndPreviousWasSkipped => MountState::OutdatedAndPreviousWasSkipped,
31+
}
32+
}
33+
34+
pub(crate) fn mark_previous_was_skipped(&mut self) {
35+
match self {
36+
MountState::MountedAndUpToDate => {
37+
*self = MountState::MountedAndUpToDateButPreviousWasSkipped
38+
}
39+
MountState::Outdated => *self = MountState::OutdatedAndPreviousWasSkipped,
40+
_ => {}
41+
}
42+
}
43+
44+
pub(crate) fn needs_reposition(&self) -> NeedsReposition {
45+
match self {
46+
MountState::MountedAndUpToDate => NeedsReposition::No {
47+
previous_skipped: false,
48+
},
49+
MountState::MountedAndUpToDateButPreviousWasSkipped => NeedsReposition::No {
50+
previous_skipped: true,
51+
},
52+
MountState::Outdated => NeedsReposition::No {
53+
previous_skipped: false,
54+
},
55+
MountState::OutdatedAndPreviousWasSkipped => NeedsReposition::No {
56+
previous_skipped: true,
57+
},
58+
MountState::OutdatedAndMoved => NeedsReposition::Yes,
59+
}
60+
}
61+
}
62+
63+
pub(crate) enum NeedsReposition {
64+
Yes,
65+
No { previous_skipped: bool },
66+
}
67+
68+
const _: () = assert!(std::mem::size_of::<NeedsReposition>() == 1);

0 commit comments

Comments
 (0)