Socket
Socket
Sign inDemoInstall

oj-diff-patch

Package Overview
Dependencies
9
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    oj-diff-patch

json diff patch repatch, undo / redo


Version published
Maintainers
1
Install size
3.26 MB
Created

Readme

Source

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" }] }

Keywords

FAQs

Last updated on 05 Jan 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc