mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
This PR copying @affine/workspace into common/infra, and adding definitions for services and unit tests.
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);
|
|
}
|