oj-diff-patch
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

DiffPatch

Uses the jsondiffpatch library

Usage

import

import { DiffPatch } from "oj-diff-patch"

Initialize

const dp = new DiffPatch()

Add change

let state = dp.add({ packages: [{ name: "oj-diff-patch", version: "1.0.0" }] })
state = dp.add({ packages: [{ name: "oj-diff-patch", version: "1.0.1" }, { name: "oj-store", version: "1.0.0" }] })

Undo / Redo

undoBtn.classList.toggle("is-disabled", !dp.canUndo())
redoBtn.classList.toggle("is-disabled", !dp.canRedo())
state = dp.undo()
// state is { packages: [{ name: "oj-diff-patch", version: "1.0.0" }] }
state = dp.redo()
// state is { packages: [{ name: "oj-diff-patch", version: "1.0.1" }, { name: "oj-store", version: "1.0.0" }] }

Reset

Removes all recoded patches, undo/redo wont be possible anymore until a new change is added. It won't change the current state.

dp.reset()

Listen

Listen to changes, get the deltas, from and to states.

state = dp.listen = (deltas, from, to) => {
  storage.set("deltas", deltas)
}

Load

Apply delta array. This will override the current state.

state = dp.load(storage.get("deltas")) // [{"packages":[{"name":"oj-diff-patch","version":"1.0.0"}]},{"packages":{"0":{"version":["1.0.0","1.0.1"]},"1":[{"name":"oj-store","version":"1.0.0"}],"_t":"a"}}]
// state is { packages: [{ name: "oj-diff-patch", version: "1.0.1" }, { name: "oj-store", version: "1.0.0" }] }

Dependencies (1)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i oj-diff-patch

    Weekly Downloads

    1

    Version

    6.0.0

    License

    MIT

    Unpacked Size

    9.57 kB

    Total Files

    6

    Last publish

    Collaborators

    • orange-juice