fix: use TreeID as external event item (#280)

This commit is contained in:
Leon Zhao 2024-02-29 20:33:06 +08:00 committed by GitHub
parent d3844ce04c
commit 80bd6936d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 13 deletions

View file

@ -22,8 +22,8 @@ pub struct TreeDiffItem {
#[derive(Debug, Clone, Copy, Serialize)]
pub enum TreeExternalDiff {
Create(TreeParentId),
Move(TreeParentId),
Create(Option<TreeID>),
Move(Option<TreeID>),
Delete,
}
@ -33,11 +33,11 @@ impl TreeDiffItem {
match item.action {
TreeInternalDiff::Create(p) => Some(TreeDiffItem {
target,
action: TreeExternalDiff::Create(p),
action: TreeExternalDiff::Create(p.into_node().ok()),
}),
TreeInternalDiff::Move(p) => Some(TreeDiffItem {
target,
action: TreeExternalDiff::Move(p),
action: TreeExternalDiff::Move(p.into_node().ok()),
}),
TreeInternalDiff::Delete(_) | TreeInternalDiff::UnCreate => Some(TreeDiffItem {
target,
@ -147,10 +147,10 @@ impl<'a> TreeValue<'a> {
match d.action {
TreeExternalDiff::Create(parent) => {
self.create_target(target);
self.mov(target, parent.as_node().copied());
self.mov(target, parent);
}
TreeExternalDiff::Delete => self.delete_target(target),
TreeExternalDiff::Move(parent) => self.mov(target, parent.as_node().copied()),
TreeExternalDiff::Move(parent) => self.mov(target, parent),
}
}
}

View file

@ -1249,7 +1249,7 @@ impl TreeHandler {
let tree_id = TreeID::from_id(txn.next_id());
let event_hint = TreeDiffItem {
target: tree_id,
action: TreeExternalDiff::Create(TreeParentId::from_tree_id(parent)),
action: TreeExternalDiff::Create(parent),
};
txn.apply_local_op(
self.container_idx,
@ -1279,7 +1279,7 @@ impl TreeHandler {
crate::op::RawOpContent::Tree(TreeOp { target, parent }),
EventHint::Tree(TreeDiffItem {
target,
action: TreeExternalDiff::Move(TreeParentId::from_tree_id(parent)),
action: TreeExternalDiff::Move(parent),
}),
&self.state,
)

View file

@ -298,7 +298,7 @@ impl ContainerState for TreeState {
};
let diff = TreeDiffItem {
target: node.id,
action: TreeExternalDiff::Create(parent),
action: TreeExternalDiff::Create(parent.into_node().ok()),
};
diffs.push(diff);
q.extend(node.children);

View file

@ -342,16 +342,14 @@ pub mod wasm {
match diff.action {
TreeExternalDiff::Create(p) => {
js_sys::Reflect::set(&obj, &"action".into(), &"create".into()).unwrap();
js_sys::Reflect::set(&obj, &"parent".into(), &p.to_tree_id().into())
.unwrap();
js_sys::Reflect::set(&obj, &"parent".into(), &p.into()).unwrap();
}
TreeExternalDiff::Delete => {
js_sys::Reflect::set(&obj, &"action".into(), &"delete".into()).unwrap();
}
TreeExternalDiff::Move(p) => {
js_sys::Reflect::set(&obj, &"action".into(), &"move".into()).unwrap();
js_sys::Reflect::set(&obj, &"parent".into(), &p.to_tree_id().into())
.unwrap();
js_sys::Reflect::set(&obj, &"parent".into(), &p.into()).unwrap();
}
}
array.push(&obj);