Skip to content

Commit

Permalink
feat(crdt-yjs): 1s merge interval (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
pluvrt authored Jan 21, 2025
1 parent 4612279 commit 820898c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-apricots-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pluv/crdt-yjs": patch
---

Increase undo/redo merge interval from 0s to 1s.
7 changes: 5 additions & 2 deletions packages/crdt-loro/src/doc/CrdtLoroDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import type { Container } from "loro-crdt";
import { LoroDoc, LoroEventBatch, LoroList, LoroMap, LoroText, UndoManager, isContainer } from "loro-crdt";
import type { LoroType } from "../types";

const MAX_UNDO_STEPS = 100;
const MERGE_INTERVAL_MS = 1_000;

export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> extends AbstractCrdtDoc<TStorage> {
public value: LoroDoc = new LoroDoc();

Expand Down Expand Up @@ -190,8 +193,8 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> ex
}

this._undoManager = new UndoManager(this.value, {
maxUndoSteps: 100,
mergeInterval: 1_000, // 1_000ms,
maxUndoSteps: MAX_UNDO_STEPS,
mergeInterval: MERGE_INTERVAL_MS,
});

return this;
Expand Down
4 changes: 3 additions & 1 deletion packages/crdt-yjs/src/doc/CrdtYjsDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import type { YjsType } from "../types";
import { YjsXmlElement } from "../xmlElement/YjsXmlElement";
import { YjsXmlText } from "../xmlText/YjsXmlText";

const MERGE_INTERVAL_MS = 1_000;

export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> extends AbstractCrdtDoc<TStorage> {
public value: YDoc = new YDoc();

Expand Down Expand Up @@ -205,7 +207,7 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>> exte
return this;
}

this._undoManager = new UndoManager(sharedTypes, { captureTimeout: 0 });
this._undoManager = new UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });

return this;
}
Expand Down

0 comments on commit 820898c

Please sign in to comment.