Skip to content

Commit

Permalink
feat(Patch): Allow passing a custom patch handler
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Feb 24, 2022
1 parent 6752a01 commit db6ea87
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions web/src/documents.ts
Expand Up @@ -230,7 +230,11 @@ export async function sendPatch(
// Handles a 'patched' event by either sending it to the relevant WebComponent
// so that it can make the necessary changes to the DOM, or by calling `applyPatch` which
// makes changes to the DOM directly.
export function receivePatch(clientId: ClientId, event: DocumentEvent): void {
export function receivePatch(
clientId: ClientId,
event: DocumentEvent,
callback: (patch: Patch) => void = applyPatch
): void {
let patch
if (event.type === 'patched') {
patch = event.patch as Patch
Expand All @@ -252,7 +256,7 @@ export function receivePatch(clientId: ClientId, event: DocumentEvent): void {
for (const op of ops) console.log(' ', JSON.stringify(op))
}

applyPatch(patch)
callback(patch)
}

/**
Expand Down

0 comments on commit db6ea87

Please sign in to comment.