Socket
Book a DemoInstallSign in
Socket

undore

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

undore

Redo/Undo

0.2.0
unpublished
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Undore

A persistent data structure to manage undos and redos

Example

var undore = require('undore');

// initialize the state to 10
var dataState = undore(10);

// operations does not mutate the original object
undore.set(dataState, 5);
console.log(undore.get(dataState)); // 10

// but we can manually reasign our variable
dataState = undore.set(dataState, 5);
console.log(undore.get(dataState)); // 5

// maybe 5 isn't really a nice value, let's rollback
dataState = undore.undo(dataState);
console.log(undore.get(dataState)); // 10

// nevermind, 5 is pretty awesome
dataState = undore.redo(dataState);
console.log(undore.get(dataState)); // 5

Operations

undore(initialState) → undore

Constructor of an Undore instance. This instance is in fact an instance of Immutable.Map with three keys:

  • state: The most recent and valid version of the state
  • history: An Immutable.Stack that contains every past versions of the state.
  • redos: Also an Immutable.Stack with changes that were undone and may be redone.

Note: Undore does not enforce the use of immutable object as its state.

undore.set(undore, value) → undore

Change the value and record the change in the history.

undore.get(undore) → value

Get the current value.

undore.update(undore, updater) → undore

Update the state with a function of previous state to next state. These are equivalent:

undore.set(myState, updater(undore.get(myState)))
undore.update(myState, updater)

undore.undo(undore) → undore

Undo the latest change if any.

undore.redo(undore) → undore

Redo the latest undo if any.

Demo

  • undore-react-example

License

MIT

Keywords

immutable

FAQs

Package last updated on 03 Mar 2015

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.