1.0.2 • Published 4 months ago

ember-undo-stack v1.0.2

Weekly downloads
594
License
Apache-2.0
Repository
github
Last release
4 months ago

ember-undo-stack

Build Status

A simple undo/redo stack for Ember.js objects

Questions? Ping me @gavinjoyce

Installation

This is an Ember CLI addon, to install:

npm install ember-undo-stack --save

Demo

undo2

Usage Instructions

Add the UndoStack mixin and implement a checkpointData computed property and a restoreCheckpoint function:

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:

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

Development Instructions

  • git clone this repository
  • npm install
  • bower install

Running

1.0.2

4 months ago

1.0.1

4 years ago

1.0.0

5 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.0.1

10 years ago