-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redo and returning true if undo/redo did anything. #11
base: master
Are you sure you want to change the base?
Conversation
the ideas sound good, but i'm a bit confused by the implementation and by some of the detail in how you describe it. can you provide some examples of how this works, and why? it would be best to get them in the form of jasmine specs, with the test suite, if you can. |
No problem! I'll write some tests this morning... Thanks, Thai On 1/9/12 4:13 PM, Derick Bailey wrote:
|
I added a redo spec to the project. Here are some notes on the details of the implementation:
Does that make sense? Thanks! |
Thanks for the explanation and the specs! Your explanation helped a lot. I still didn't quite follow what the A few suggestions on that... The name 'finalRedoState' seems a little odd to me. When I read the spec, I keep thinking about tracking dirty state. What do you think of changing that to "dirtyState"? And the functionality may not be clearly defined for all the cases I can think of. What happens in these scenarios:
I don't really know what I would expect these to do, off-hand... but these types of scenarios (any others, too?) need to at least be accounted for in the specs and documentation so that we know what to expect from code like this. Thanks again for the work on this. It's looking great! |
dirtyState makes sense to me. I just pushed that. As for the scenarios you mentioned:
|
1 & 3 - that makes sense. 2 ... hmm... in thinking about standard undo / redo functionality, if i undo something and then make a change, my path through the changes is now different and there is no more redo functionality because I'm now travelling a different path. would it make sense for this to work the same way? so... in this example:
Right now when I call restore, it changes foo back to "bar". then after I have made changes and call redo, it sets bar to "baz". In the standard undo/redo path travelling, calling restore would set foo back to "bar" and then the set{foo: "quux"} would wipe out the remaining states in the queue because I started down another path. then, "redo" would not change anything because there is no where to go. I can see reason to do it the current way, and to change it to what i just described. my inclination is to change it because most people are going to expect undo/redo to work in this manner. what do you think? |
If any change to the model is preceded by a store(), then it would work Right now, Memento doesn't know when the model changes and implementing Similarly, if calling "set" without a store() is going to impact
Should the second "restore()" set foo back to "baz" or leave it at Ultimately, I'm assuming that users of Memento will call store() before If you do choose to make that Memento aware of that last "set()" and On 1/10/12 6:05 PM, Derick Bailey wrote:
|
Quick ping to see if you're still interested in this pull request. Is there anything else you suggest? Thanks. |
d'oh! i completely forgot about this. :( sorry. i'll get this pulled in soon. i've been buried under my email lately, and digging myself out slowly. |
+1 |
Looks like good stuff. I'm in need of a library like Memento and the redo functionality would be a great addition. Would love to see it merged, when you get the chance. |
Anyone knows an alternative to this? |
I added two features that we needed for our app.
The larger one is redo. It doesn't pop states off the stack, but instead keeps an index to the next state that should be returned by undo. If a store() is called while the index is in the middle of the stack, it truncates the array to remove the remain states that should no longer be accessible.
Because store() is usually called before an action is performed on the model, there are generally some unsaved changes to the model when you call undo. These unsaved changes are stored in a temporary attributes variable so they can be redone (redo'ed?).
I also return true if an undo() or redo() call actually applies attributes to the model. If nothing is applied, it returns false.