https://github.com/intercom/ember-undo-stack
:repeat: An undo/redo stack for Ember.js objects
https://github.com/intercom/ember-undo-stack
Last synced: 10 months ago
JSON representation
:repeat: An undo/redo stack for Ember.js objects
- Host: GitHub
- URL: https://github.com/intercom/ember-undo-stack
- Owner: intercom
- License: apache-2.0
- Created: 2014-10-18T20:05:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-03-26T09:11:36.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T07:07:54.365Z (almost 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 1.09 MB
- Stars: 116
- Watchers: 183
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ember-undo-stack
[](https://travis-ci.org/intercom/ember-undo-stack)
A simple undo/redo stack for Ember.js objects
Questions? Ping me [@gavinjoyce](https://twitter.com/gavinjoyce)
## Installation
This is an Ember CLI addon, to install:
`npm install ember-undo-stack --save`
## Demo

## Usage Instructions
Add the `UndoStack` mixin and implement a `checkpointData` computed property and a `restoreCheckpoint` function:
```javascript
var Cat = Ember.Object.extend(UndoStack, {
name: 'Sully',
color: 'Black',
checkpointData: function() {
return {
name: this.get('name'),
color: this.get('color')
}
}.property('name', 'color'),
restoreCheckpoint: function(data) {
this.setProperties({
name: data.name,
color: data.color
});
}
})
```
The `UndoStack` mixin adds `checkpoint`, `undo` and `redo` functions to your object which can be used as follows:
```javascript
var cat = Cat.create({
name: 'Sooty',
color: 'Black'
});
cat.checkpoint();
cat.set('name', 'Hugo');
cat.checkpoint();
cat.undo();
cat.get('name'); // => 'Sooty'
cat.redo();
cat.get('name'); // => 'Hugo'
```
A `throttledCheckpoint` function and `undoCheckpointThrottleInMilliseconds` property are also added.
## TODOs
* [ ] Create a few sample applications
* [ ] Store a diff between checkpoints instead of a copy (https://github.com/intercom/ember-undo-stack/issues/4)
## Development Instructions
* `git clone` this repository
* `npm install`
* `bower install`
### Running
* `ember server`
* Visit your app at http://localhost:4200.