-
Notifications
You must be signed in to change notification settings - Fork 2
Description
When users scale or drag an element on the canvas, should we sync those temporary states in real time? If we push everything through LoroDoc, the editing history will be filled with redundant operations. But syncing in real time can still be very useful.
The proposed solution is to combine LoroDoc with EphemeralStore. We can use EphemeralStore to sync the temporary state deltas, and only commit the final value after a timeout. This way, we get the benefits of both real-time responsiveness and a clean, efficient history.
Example
const doc = new LoroDoc();
const eph = new EphemeralStore();
const m = new Mirror({
doc,
ephemeralPatch: eph
});
m.setStateWithEphemeralPatch(
s => s.items[5] = {x: 100, y: 200},
{finalizeTimeout: 1_000}
)
The EphemeralStore should store the patch like:
{
"cid:12@123:Map": {
"x": { "v": 100, "lastOp": "10@123" },
"y": { "v": 200, "lastOp": "9@123" }
}
}
It can only patch the value if the lastOp is aligned. So if another collaborator changes the value through LoroDoc concurrently, the lib will prefer the new value from the collaborator.