@stephen/automerge-patcher
TypeScript icon, indicating that this package has built-in type declarations

0.8.0-alpha.6-patchobject • Public • Published

Automerge Patcher

Utility functions to apply and invert patches generated by Automerge document changes.

Installation

npm install @onsetsoftware/automerge-patcher

Usage

import { patch, unpatch } from '@onsetsoftware/automerge-patcher';
import {from} from "@automerge/automerge";

const doc = from({foo: 'bar'});

let patch;

const doc2 = change(
  doc,
  {
    patchCallback: (p, old) => {
      // capture inverse of each patch for undo
      patch = unpatch(old, p);
    }
  },
  (doc) => {
    doc.foo = 'baz';
  }
);

console.log(patch); // {action: 'put', path: ['foo'], value: 'bar'}
console.log(doc2.foo); // baz

const doc3 = change(doc2, (doc) => {
  // apply the patch to revert the change
  applyPatch(doc, patch);
});

console.log(doc3.foo); // bar

Readme

Keywords

none

Package Sidebar

Install

npm i @stephen/automerge-patcher

Weekly Downloads

0

Version

0.8.0-alpha.6-patchobject

License

none

Unpacked Size

13.7 kB

Total Files

9

Last publish

Collaborators

  • stephen