https://github.com/ericgj/model-undoable
undo/redo behavior for component/model
https://github.com/ericgj/model-undoable
Last synced: about 1 year ago
JSON representation
undo/redo behavior for component/model
- Host: GitHub
- URL: https://github.com/ericgj/model-undoable
- Owner: ericgj
- Created: 2013-07-07T20:59:30.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-06-21T17:58:22.000Z (almost 11 years ago)
- Last Synced: 2025-04-13T06:15:48.002Z (about 1 year ago)
- Language: JavaScript
- Size: 181 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# model-undoable
Undo/redo behavior for component/model-ish classes/objects
## Installation
$ component install ericgj/model-undoable
## Examples
For component/model, just `use` the plugin:
```javascript
var undoable = require('model-undoable')
, model = require('model')
var Person = model('person')
.attr('id')
.attr('name')
.attr('email')
.use(undoable);
```
Now your model instances have `undo`, `redo`, `undoAll`, `redoAll` methods.
- `undo` and `redo` work as expected on individual model changes.
- `undoAll` undoes all changes back to the last save.
- `redoAll` redoes all undone changes from the last save to the most current.
- Model instances will also emit `undo` and `redo` events.
You can also mix it into model instances directly (or into similar objects that
emit `change` events such as [react][react]-ified objects):
```javascript
var undoable = require('model-undoable')
var person = new Person();
undoable(person);
```
## Motivation
Mainly I wrote it for `undoAll` for reverting all changes made in a reactive
view. Obviously most browsers give you individual undo/redo.
## License
MIT
[react]: https://github.com/timoxley/react