Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Add canUndo and canRedo
Browse files Browse the repository at this point in the history
  • Loading branch information
pangratz committed May 16, 2012
1 parent c1af27e commit 53f1702
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/lib/memento.js
Expand Up @@ -20,6 +20,14 @@ Ember.Memento = Ember.Mixin.create({
return length - mementoIndex - 1;
}.property('_mementoIndex', '_memento.length').cacheable(),

canUndo: function() {
return this.get('undoCount') > 0;
}.property('undoCount').cacheable(),

canRedo: function() {
return this.get('redoCount') > 0;
}.property('redoCount').cacheable(),

_mementoSizeChanged: function() {
this._updateMemento();
}.observes('mementoSize'),
Expand Down
51 changes: 51 additions & 0 deletions app/tests/memento_tests.js
Expand Up @@ -635,6 +635,57 @@ function() {
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');
});

module("canUndo AND canRedo", {
teardown: cleanObj
});

test("they are true when a undo/redo is possible",
function() {
obj = Ember.Object.create(Ember.Memento, {
mementoProperties: 'str'.w(),

str: 'frozen'
});

equal(get(obj, 'canUndo'), false);
equal(get(obj, 'canRedo'), false);

set(obj, 'str', 'banana');

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), false);

set(obj, 'str', 'Frozen Banana');

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), false);

obj.undo();

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), true);

obj.undo();

equal(get(obj, 'canUndo'), false);
equal(get(obj, 'canRedo'), true);

obj.redo();

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), true);

obj.redo();

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), false);

obj.redo();

equal(get(obj, 'canUndo'), true);
equal(get(obj, 'canRedo'), false);
});

module("clearHistory", {
teardown: cleanObj
});
Expand Down

0 comments on commit 53f1702

Please sign in to comment.