import { CollabOrigin } from '@/application/types'; import * as Y from 'yjs'; /** * Apply doc state from server to client * Note: origin is always remote * @param doc local Y.Doc * @param state state from server */ export function applyYDoc(doc: Y.Doc, state: Uint8Array) { Y.transact( doc, () => { try { Y.applyUpdate(doc, state, CollabOrigin.Remote); } catch (e) { console.error('Error applying', doc, e); throw e; } }, CollabOrigin.Remote ); }