fix: from snapshot should enable auto commit

This commit is contained in:
Zixuan Chen 2023-11-17 23:05:20 +08:00
parent 089d05e3a0
commit b940214985
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -238,7 +238,8 @@ impl Loro {
///
#[wasm_bindgen(js_name = "fromSnapshot")]
pub fn from_snapshot(snapshot: &[u8]) -> JsResult<Loro> {
let doc = LoroDoc::from_snapshot(snapshot)?;
let mut doc = LoroDoc::from_snapshot(snapshot)?;
doc.start_auto_commit();
Ok(Loro(doc))
}

View file

@ -129,6 +129,15 @@ describe("import", () => {
a.import(b.exportFrom(a.version()));
expect(a.getText("text").toString()).toBe("abc");
});
it("from snapshot", () => {
const a = new Loro();
a.getText("text").insert(0, "hello");
const bytes = a.exportSnapshot();
const b = Loro.fromSnapshot(bytes);
b.getText("text").insert(0, "123");
expect(b.toJson()).toStrictEqual({ "text": "123hello" })
})
});
describe("map", () => {