mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
18 lines
399 B
TypeScript
18 lines
399 B
TypeScript
import { applyUpdate, Doc, encodeStateAsUpdate } from 'yjs';
|
|
|
|
export function mergeUpdates(updates: Uint8Array[]) {
|
|
if (updates.length === 0) {
|
|
return new Uint8Array();
|
|
}
|
|
if (updates.length === 1) {
|
|
return updates[0];
|
|
}
|
|
const doc = new Doc();
|
|
doc.transact(() => {
|
|
updates.forEach(update => {
|
|
applyUpdate(doc, update);
|
|
});
|
|
});
|
|
return encodeStateAsUpdate(doc);
|
|
}
|