Hi as we have been talking in Twitter, I need to extend the Entry Model to add a new prop.
In my case, I have something like this:
AddUndoState:
addUndoState(recorder) {
if (recorder.patches.length === 0) {
return;
}
if (replaying) {
// skip recording if this state was caused by undo / redo
return;
}
self.history.splice(self.undoIdx);
self.history.push({
zoom: $('#canva').css('transform'),
patches: recorder.patches,
inversePatches: recorder.inversePatches
});
self.undoIdx = self.history.length;
}
I need to save the css transform in the history, because if the action was in a different "environment" (zoomed, for example), if I revert the change, I have an issue with my selector. We are not recording nothing about the zoom.
I need to extend the entry model to something like this:
In the other hand, to solve my problem, I can pass a callback to the undo/redo action, and check if the "environment" is different and process in the correct way:
undo(callback) {
replaying = true;
self.undoIdx -= 1;
const { zoom } = self.history[self.undoIdx];
// n.b: reverse patches back to forth
// TODO: add error handling when patching fails? E.g. make the operation atomic?
mst.applyPatch(
targetStore,
self.history[self.undoIdx].inversePatches.slice().reverse()
);
replaying = false;
callback(zoom);
}
My callback function:
function example_callback(zoom){
if (
!!rootStore.canvaStore.selector &&
zoom !== $('#canva').css('transform')
) {
// DO CUSTOM STUFF HERE
}
}
I have this working, but I have copied the code of the undoManager and I have added to my project, but I don't want to do it... any ideas? Thanks @mweststrate & @robinfehr
Hi as we have been talking in Twitter, I need to extend the Entry Model to add a new prop.
In my case, I have something like this:
AddUndoState:
I need to save the css transform in the history, because if the action was in a different "environment" (zoomed, for example), if I revert the change, I have an issue with my selector. We are not recording nothing about the zoom.
I need to extend the entry model to something like this:
In the other hand, to solve my problem, I can pass a callback to the undo/redo action, and check if the "environment" is different and process in the correct way:
My callback function:
I have this working, but I have copied the code of the undoManager and I have added to my project, but I don't want to do it... any ideas? Thanks @mweststrate & @robinfehr