https://github.com/izure1/undoit
Simple undo, redo system for JavaScript/TypeScript.
https://github.com/izure1/undoit
undo undo-redo
Last synced: 3 months ago
JSON representation
Simple undo, redo system for JavaScript/TypeScript.
- Host: GitHub
- URL: https://github.com/izure1/undoit
- Owner: izure1
- License: mit
- Created: 2023-04-24T18:08:14.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-13T21:18:13.000Z (over 1 year ago)
- Last Synced: 2025-09-15T11:55:59.607Z (7 months ago)
- Topics: undo, undo-redo
- Language: TypeScript
- Homepage:
- Size: 67.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Undoit
[](https://www.jsdelivr.com/package/npm/undoit)

Simple undo, redo system for JavaScript/TypeScript.
## How to use
```typescript
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
```typescript
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
```typescript
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](https://www.npmjs.com/package/undoit)|
|**Github**|[View](https://github.com/izure1/undoit)|
|**jsdelivr**|[Download](https://cdn.jsdelivr.net/npm/undoit@1.x.x/dist/esm/index.min.js)|
### Node.js (commonjs)
```bash
npm i undoit
```
### Browser (esmodule)
```html
import { Action, UndoRedo } from 'https://cdn.jsdelivr.net/npm/undoit@1.x.x/dist/esm/index.min.js'
```
## License
MIT LICENSE