fix: forkAt should inherit the config and auto commit from the original doc

This commit is contained in:
Zixuan Chen 2024-10-19 22:46:41 +08:00
parent 7860702dc1
commit efad275e1a
No known key found for this signature in database
2 changed files with 24 additions and 0 deletions

View file

@ -41,6 +41,10 @@ impl LoroDoc {
})
.unwrap();
let doc = LoroDoc::new();
doc.set_config(&self.config);
if self.auto_commit.load(std::sync::atomic::Ordering::Relaxed) {
doc.start_auto_commit();
}
doc.import(&bytes).unwrap();
doc
}

View file

@ -290,6 +290,26 @@ describe("to json", () => {
});
});
it("fork at", () => {
const doc = new LoroDoc();
doc.setPeerId("0");
doc.getText("text").insert(0, "Hello, world!");
console.log("0");
const newDoc = doc.forkAt([{ peer: "0", counter: 6 }]);
newDoc.setPeerId("1");
newDoc.getText("text").insert(6, " Alice!");
// ┌───────────────┐ ┌───────────────┐
// │ Hello, │◀─┬──│ world! │
// └───────────────┘ │ └───────────────┘
// │
// │ ┌───────────────┐
// └──│ Alice! │
// └───────────────┘
doc.import(newDoc.export({ mode: "update" }));
console.log(doc.getText("text").toString()); // "Hello, world! Alice!"
});
function one_ms(): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, 1));
}