mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 12:57:20 +00:00
fix: forkAt should inherit the config and auto commit from the original doc
This commit is contained in:
parent
7860702dc1
commit
efad275e1a
2 changed files with 24 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue