Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

399 B
Raw Blame
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);
}