mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-05 20:17:13 +00:00
refactor: refine movable list internal event
This commit is contained in:
parent
e13c7ff174
commit
7e7fe782b4
4 changed files with 24 additions and 21 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -201,9 +201,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
|||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.6.0"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
||||
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
|
@ -1873,9 +1873,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "serde_columnar"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06a86f5f6dc16d8308c37e145dd4c7e60fba1486d84982519388d31ea0ad6703"
|
||||
checksum = "7947238638e841d935a1dadff54b74575ae60d51b977be75dab16e7638ea6e7d"
|
||||
dependencies = [
|
||||
"itertools 0.11.0",
|
||||
"postcard",
|
||||
|
|
|
@ -36,21 +36,21 @@ impl MovableListInnerDelta {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ElementDelta {
|
||||
pub pos: IdLp,
|
||||
pub pos_updated: bool,
|
||||
/// This must be Some if it's in checkout mode (not fast-forward mode)
|
||||
pub pos: Option<IdLp>,
|
||||
pub value: LoroValue,
|
||||
pub value_updated: bool,
|
||||
pub value_id: IdLp,
|
||||
/// This must be Some if it's in checkout mode (not fast-forward mode)
|
||||
pub value_id: Option<IdLp>,
|
||||
}
|
||||
|
||||
impl ElementDelta {
|
||||
pub fn placeholder() -> Self {
|
||||
Self {
|
||||
pos: IdLp::NONE_ID,
|
||||
pos_updated: false,
|
||||
pos: None,
|
||||
value: LoroValue::Null,
|
||||
value_updated: false,
|
||||
value_id: IdLp::NONE_ID,
|
||||
value_id: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1048,20 +1048,18 @@ impl DiffCalculatorTrait for MovableListDiffCalculator {
|
|||
on_new_container(c);
|
||||
}
|
||||
*change = ElementDelta {
|
||||
pos: pos.idlp(),
|
||||
pos: Some(pos.idlp()),
|
||||
value: value.value.clone(),
|
||||
value_id: IdLp::new(value.peer, value.lamport),
|
||||
pos_updated: true,
|
||||
value_id: Some(IdLp::new(value.peer, value.lamport)),
|
||||
value_updated: true,
|
||||
};
|
||||
} else {
|
||||
// TODO: PERF: can be filtered based on the list_diff and whether the pos/value are updated
|
||||
*change = ElementDelta {
|
||||
pos: pos.idlp(),
|
||||
pos_updated: old_pos.unwrap().idlp() != pos.idlp(),
|
||||
pos: Some(pos.idlp()),
|
||||
value: value.value.clone(),
|
||||
value_updated: old_value.unwrap().value != value.value,
|
||||
value_id: IdLp::new(value.peer, value.lamport),
|
||||
value_id: Some(IdLp::new(value.peer, value.lamport)),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1059,7 +1059,6 @@ impl ContainerState for MovableListState {
|
|||
for (elem_id, delta_item) in diff.elements.into_iter() {
|
||||
let crate::delta::ElementDelta {
|
||||
pos,
|
||||
pos_updated: _,
|
||||
value,
|
||||
value_updated,
|
||||
value_id,
|
||||
|
@ -1072,7 +1071,8 @@ impl ContainerState for MovableListState {
|
|||
// Update value if needed
|
||||
if elem.value != value {
|
||||
maybe_moved.remove(&elem_id);
|
||||
self.inner.update_value(elem_id, value.clone(), value_id);
|
||||
self.inner
|
||||
.update_value(elem_id, value.clone(), value_id.unwrap());
|
||||
let index = self.get_index_of_elem(elem_id);
|
||||
if let Some(index) = index {
|
||||
event.compose(
|
||||
|
@ -1091,9 +1091,9 @@ impl ContainerState for MovableListState {
|
|||
}
|
||||
|
||||
// Update pos if needed
|
||||
if elem.pos != pos {
|
||||
if elem.pos != pos.unwrap() {
|
||||
// don't need to update old list item, because it's handled by list diff already
|
||||
let result = self.inner.update_pos(elem_id, pos, false);
|
||||
let result = self.inner.update_pos(elem_id, pos.unwrap(), false);
|
||||
let result = self.inner.convert_update_to_event_pos(result);
|
||||
if let Some(new_index) = result.insert {
|
||||
let new_value =
|
||||
|
@ -1135,7 +1135,12 @@ impl ContainerState for MovableListState {
|
|||
}
|
||||
None => {
|
||||
// Need to create new element
|
||||
let result = self.create_new_elem(elem_id, pos, value.clone(), value_id);
|
||||
let result = self.create_new_elem(
|
||||
elem_id,
|
||||
pos.unwrap(),
|
||||
value.clone(),
|
||||
value_id.unwrap(),
|
||||
);
|
||||
// Composing events
|
||||
let result = self.inner.convert_update_to_event_pos(result);
|
||||
// Create event for pos change and value change
|
||||
|
|
Loading…
Reference in a new issue