Skip to content

Commit

Permalink
chore: rename tree event
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeeon233 committed Oct 19, 2024
1 parent 8e2e075 commit a13db71
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
19 changes: 18 additions & 1 deletion crates/loro-internal/examples/encoding.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Instant;

use bench_utils::TextAction;
use loro_internal::LoroDoc;
use loro_internal::{loro::ExportMode, LoroDoc};

fn main() {
let actions = bench_utils::get_automerge_actions();
Expand Down Expand Up @@ -54,6 +54,23 @@ fn main() {
output.len(),
);

let start = Instant::now();
let shallow_snapshot = loro
.export(ExportMode::shallow_snapshot(&loro.oplog_frontiers()))
.unwrap();
println!("Shallow Snapshot time {}ms", start.elapsed().as_millis());
let output = miniz_oxide::deflate::compress_to_vec(&shallow_snapshot, 6);
println!(
"Shallow Snapshot+compression time {}ms",
start.elapsed().as_millis()
);

println!(
"Shallow snapshot size {} after compression {}",
shallow_snapshot.len(),
output.len(),
);

let updates = loro.export_from(&Default::default());
let output = miniz_oxide::deflate::compress_to_vec(&updates, 6);
println!(
Expand Down
12 changes: 6 additions & 6 deletions crates/loro-internal/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ pub mod wasm {
js_sys::Reflect::set(&obj, &"index".into(), &(*index).into()).unwrap();
js_sys::Reflect::set(
&obj,
&"fractional_index".into(),
&"fractionalIndex".into(),
&position.to_string().into(),
)
.unwrap();
Expand All @@ -578,11 +578,11 @@ pub mod wasm {
js_sys::Reflect::set(&obj, &"action".into(), &"delete".into()).unwrap();
js_sys::Reflect::set(
&obj,
&"old_parent".into(),
&"oldParent".into(),
&JsValue::from(old_parent.tree_id()),
)
.unwrap();
js_sys::Reflect::set(&obj, &"old_index".into(), &(*old_index).into())
js_sys::Reflect::set(&obj, &"oldIndex".into(), &(*old_index).into())
.unwrap();
}
TreeExternalDiff::Move {
Expand All @@ -602,17 +602,17 @@ pub mod wasm {
js_sys::Reflect::set(&obj, &"index".into(), &(*index).into()).unwrap();
js_sys::Reflect::set(
&obj,
&"fractional_index".into(),
&"fractionalIndex".into(),
&position.to_string().into(),
)
.unwrap();
js_sys::Reflect::set(
&obj,
&"old_parent".into(),
&"oldParent".into(),
&JsValue::from(old_parent.tree_id()),
)
.unwrap();
js_sys::Reflect::set(&obj, &"old_index".into(), &(*old_index).into())
js_sys::Reflect::set(&obj, &"oldIndex".into(), &(*old_index).into())
.unwrap();
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/loro-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3525,7 +3525,7 @@ impl LoroTree {
js_sys::Reflect::set(&obj, &"index".into(), &JsValue::from(index))?;
js_sys::Reflect::set(
&obj,
&"fractional_index".into(),
&"fractionalIndex".into(),
&JsValue::from_str(&position),
)?;
js_sys::Reflect::set(&obj, &"meta".into(), &map.into())?;
Expand Down
10 changes: 5 additions & 5 deletions loro-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ export type TreeDiffItem =
action: "create";
parent: TreeID | undefined;
index: number;
fractional_index: string;
fractionalIndex: string;
}
| { target: TreeID; action: "delete"; old_parent: TreeID | undefined; old_index: number }
| { target: TreeID; action: "delete"; oldParent: TreeID | undefined; oldIndex: number }
| {
target: TreeID;
action: "move";
parent: TreeID | undefined;
index: number;
fractional_index: string;
old_parent: TreeID | undefined;
old_index: number;
fractionalIndex: string;
oldParent: TreeID | undefined;
oldIndex: number;
};

export type TreeDiff = {
Expand Down
1 change: 1 addition & 0 deletions loro-js/tests/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ describe("type", () => {
describe("list stable position", () => {
it("basic tests", () => {
const loro = new LoroDoc();
loro.oplogFrontiers
const list = loro.getList("list");
list.insert(0, "a");
const pos0 = list.getCursor(0);
Expand Down
6 changes: 3 additions & 3 deletions loro-js/tests/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("loro tree", () => {
assert(keys.includes("id"));
assert(keys.includes("parent"));
assert(keys.includes("index"));
assert(keys.includes("fractional_index"));
assert(keys.includes("fractionalIndex"));
assert(keys.includes("meta"));
assert(keys.includes("children"));
});
Expand Down Expand Up @@ -212,8 +212,8 @@ describe("loro tree node", () => {
if (e.events[0].diff.type == "tree") {
const diff = e.events[0].diff as TreeDiff;
if (diff.diff[0].action == "move") {
assertEquals(diff.diff[0].old_parent, root.id);
assertEquals(diff.diff[0].old_index, 1);
assertEquals(diff.diff[0].oldParent, root.id);
assertEquals(diff.diff[0].oldIndex, 1);
}
}
});
Expand Down

0 comments on commit a13db71

Please sign in to comment.