Skip to content

Commit

Permalink
chore: rename wasm export from
Browse files Browse the repository at this point in the history
  • Loading branch information
Leeeon233 committed Oct 18, 2024
1 parent 2110a4e commit cdfc8f8
Show file tree
Hide file tree
Showing 4 changed files with 2,302 additions and 2,917 deletions.
16 changes: 8 additions & 8 deletions crates/loro-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ impl LoroDoc {
///
/// @param mode - The export mode to use. Can be one of:
/// - `{ mode: "snapshot" }`: Export a full snapshot of the document.
/// - `{ mode: "update", start_vv: VersionVector }`: Export updates from the given version vector.
/// - `{ mode: "update", from: VersionVector }`: Export updates from the given version vector.
/// - `{ mode: "updates-in-range", spans: { id: ID, len: number }[] }`: Export updates within the specified ID spans.
/// - `{ mode: "shallow-snapshot", frontiers: Frontiers }`: Export a garbage-collected snapshot up to the given frontiers.
///
Expand All @@ -1070,7 +1070,7 @@ impl LoroDoc {
/// // Export updates from a specific version
/// const vv = doc.oplogVersion();
/// doc.setText("text", "Hello Loro");
/// const updateBytes = doc.export({ mode: "update", start_vv: vv });
/// const updateBytes = doc.export({ mode: "update", from: vv });
///
/// // Export a garbage-collected snapshot
/// const gcBytes = doc.export({ mode: "shallow-snapshot", frontiers: doc.oplogFrontiers() });
Expand Down Expand Up @@ -4215,13 +4215,13 @@ fn js_to_export_mode(js_mode: JsExportMode) -> JsResult<ExportMode<'static>> {

match mode.as_str() {
"update" => {
let start_vv = js_sys::Reflect::get(&js_value, &JsValue::from_str("start_vv"))?;
if start_vv.is_undefined() {
let from = js_sys::Reflect::get(&js_value, &JsValue::from_str("from"))?;
if from.is_undefined() {
Ok(ExportMode::all_updates())
} else {
let start_vv = js_to_version_vector(start_vv)?;
let from = js_to_version_vector(from)?;
// TODO: PERF: avoid this clone
Ok(ExportMode::updates_owned(start_vv.0.clone()))
Ok(ExportMode::updates_owned(from.0.clone()))
}
}
"snapshot" => Ok(ExportMode::Snapshot),
Expand Down Expand Up @@ -4309,7 +4309,7 @@ interface LoroDoc {
/**
* Export updates from the specific version to the current version
*
* @deprecated Use `export({mode: "update", start_vv: version})` instead
* @deprecated Use `export({mode: "update", from: version})` instead
*
* @example
* ```ts
Expand Down Expand Up @@ -4669,7 +4669,7 @@ export type JsonChange = {
export type ExportMode = {
mode: "update",
start_vv?: VersionVector,
from?: VersionVector,
} | {
mode: "snapshot",
} | {
Expand Down
2 changes: 1 addition & 1 deletion loro-js/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ describe("export", () => {
const doc = new LoroDoc();
doc.getText("text").insert(0, "123");
doc.commit();
const updates = doc.export({ mode: "update", start_vv: new VersionVector(null) });
const updates = doc.export({ mode: "update", from: new VersionVector(null) });
const doc2 = new LoroDoc();
doc2.import(updates);
expect(doc2.toJSON()).toStrictEqual({ text: "123" });
Expand Down
4 changes: 2 additions & 2 deletions loro-js/tests/gc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("gc", () => {
doc.getList("list").delete(1, 1); // Delete "B"
doc.getMap("map").set("key", "value"); // Add a new key-value pair to a map

const updatedBytes = doc.export({ mode: "update", start_vv: newDoc.version() });
const updatedBytes = doc.export({ mode: "update", from: newDoc.version() });
newDoc.import(updatedBytes);
expect(newDoc.toJSON()).toEqual(doc.toJSON());
});
Expand All @@ -38,7 +38,7 @@ describe("gc", () => {
const docB = doc.fork();
const v = docB.version();
docB.getList("list").insert(1, "C");
const updates = docB.export({ mode: "update", start_vv: v });
const updates = docB.export({ mode: "update", from: v });

doc.getList("list").insert(1, "B");
doc.getList("list").insert(2, "C");
Expand Down
Loading

0 comments on commit cdfc8f8

Please sign in to comment.