See the issue no 1 for the background, a 2x pane ui with an Observe.List rendered to a summary panel on the left which can be clicked to render the particular item in question to an editing panel on the right. I suspect these 2x issues might be inter-related somehow.
I've implemented an undo system so the user can backtrack through a series of edits as required, and to support this I have the following
1. an undoStack initialised as an empty raw javascript array.
2. a javascript array of objects reflecting the entries in the left pane and its observable equivalent created by 'new can.Observe.List(rawDataArray)'. The left summary pane is rendered using this observable.
3. one of the observable objects is then rendered into the right pane for editing and subsequent saving.
My strategy is to re-create a copy of rawDataArray from the current state of the observable and to push that onto the undo stack. I can then retreive it an rebuild the observable using observable.replace(myUndoStackEntry), live binding kicks in and voila! I have undone to the state as at the stack entry point. The critical piece is using the obserable to rebuild a snapshot of the original data that was used to create it.
Snapshotting the Observe.List (using underscore)
=======================
undoStack = [];
newRawData = [];
_.each(observable, function(o) {
// this should lose all canjs stuff and give me back my original data ... ??
var obj = _.extend(o._data, {});
newRawData.push(obj);
});
undoStack.push(newRawData);
Inspecting via debug shows that everything is as I expect it to be, my data, with no apparent references to canjs stuff on the undo stack.
3. There is then an edit to the entry in Observe.List which is a single line of code :
currentObservableListEntry.attr('result', 'my new value');
Live binding kicks in, the left hand summary reflects the change as expected and Bingo !
However
=======
The newly created undoStack entry ALSO REFLECTS the live binding change and is behaving as if it were itself a can.Observe !
WTF ...
Clearly my attempt to strip all necessary canjs links out of the observable to go back to the raw data that created it were not entirely successful.
What have I overlooked ? Is there a better way to approach the problem ??
Is there a CAN.onical way to totally undo a can.Observe(originalData) so that you get back originalData ???
Ron Yuen
I've implemented an undo system so the user can backtrack through a series of edits as required, and to support this I have the following
1. an undoStack initialised as an empty raw javascript array.
2. a javascript array of objects reflecting the entries in the left pane and its observable equivalent created by 'new can.Observe.List(rawDataArray)'. The left summary pane is rendered using this observable.
3. one of the observable objects is then rendered into the right pane for editing and subsequent saving.
My strategy is to re-create a copy of rawDataArray from the current state of the observable and to push that onto the undo stack. I can then retreive it an rebuild the observable using observable.replace(myUndoStackEntry), live binding kicks in and voila! I have undone to the state as at the stack entry point. The critical piece is using the obserable to rebuild a snapshot of the original data that was used to create it.
Snapshotting the Observe.List (using underscore)
=======================
undoStack = [];
newRawData = [];
_.each(observable, function(o) {
// this should lose all canjs stuff and give me back my original data ... ??
var obj = _.extend(o._data, {});
newRawData.push(obj);
});
undoStack.push(newRawData);
Inspecting via debug shows that everything is as I expect it to be, my data, with no apparent references to canjs stuff on the undo stack.
3. There is then an edit to the entry in Observe.List which is a single line of code :
currentObservableListEntry.attr('result', 'my new value');
Live binding kicks in, the left hand summary reflects the change as expected and Bingo !
However
=======
The newly created undoStack entry ALSO REFLECTS the live binding change and is behaving as if it were itself a can.Observe !
WTF ...
Clearly my attempt to strip all necessary canjs links out of the observable to go back to the raw data that created it were not entirely successful.
What have I overlooked ? Is there a better way to approach the problem ??
Is there a CAN.onical way to totally undo a can.Observe(originalData) so that you get back originalData ???
Ron Yuen