Skip to content
/ undoit Public

Simple undo, redo system for JavaScript/TypeScript.

License

Notifications You must be signed in to change notification settings

izure1/undoit

Repository files navigation

Undoit

Node.js Workflow

Simple undo, redo system for JavaScript/TypeScript.

How to use

import { Action, UndoRedo } from 'undoit'

const command = new UndoRedo()
let acc = 0

const execute = () => {
  acc++
}
const undo = () => {
  acc--
}

command.execute(new Action(execute, undo))
acc // 1
command.undo()
acc // 0
command.redo()
acc // 1

Work asynchronously

import { AsyncAction, AsyncUndoRedo } from 'undoit'

const command = new AsyncUndoRedo()
let acc = 0

function delay(interval) {
  return new Promise((resolve) => {
    setTimeout(resolve, interval)
  })
}

const execute = async () => {
  await delay(100)
  acc++
}
const undo = async () => {
  await delay(100)
  acc--
}

await command.execute(new AsyncAction(execute, undo))
acc // 1
await command.undo()
acc // 0
await command.redo()
acc // 1

// without a await keyword
command.undo()
command.isBusy // true

Manage easily with state history

import { StateHistory } from 'undoit'

const initialValue = 1
const history = new StateHistory(1)

history.data // 1

history.push(2)
history.data // 2

history.undo()
history.data // 1

history.redo()
history.data // 2

Install

Site Link
NPM View
Github View
jsdelivr Download

Node.js (commonjs)

npm i undoit

Browser (esmodule)

<script type="module">
  import { Action, UndoRedo } from 'https://cdn.jsdelivr.net/npm/undoit@1.x.x/dist/esm/index.min.js'
</script>

License

MIT LICENSE

About

Simple undo, redo system for JavaScript/TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published