From 7523af09f0b799c2b5cf4ee6fe7f0855fe880978 Mon Sep 17 00:00:00 2001 From: DD Date: Thu, 5 Oct 2017 18:12:28 -0400 Subject: [PATCH] add missing file --- src/helper/undo.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/helper/undo.js diff --git a/src/helper/undo.js b/src/helper/undo.js new file mode 100644 index 00000000..449aa834 --- /dev/null +++ b/src/helper/undo.js @@ -0,0 +1,45 @@ +// undo functionality +// modifed from https://github.com/memononen/stylii +import paper from 'paper'; + +const performSnapshot = function (dispatchPerformSnapshot) { + dispatchPerformSnapshot({ + json: paper.project.exportJSON({asString: false}) + }); + + // @todo enable/disable buttons + // updateButtonVisibility(); +}; + +const _restore = function (entry) { + paper.project.clear(); + paper.project.importJSON(entry.json); + paper.view.update(); +}; + +const performUndo = function (undoState, dispatchPerformUndo) { + if (undoState.pointer > 0) { + _restore(undoState.stack[undoState.pointer - 1]); + dispatchPerformUndo(); + + // @todo enable/disable buttons + // updateButtonVisibility(); + } +}; + + +const performRedo = function (undoState, dispatchPerformRedo) { + if (undoState.pointer >= 0 && undoState.pointer < undoState.stack.length - 1) { + _restore(undoState.stack[undoState.pointer + 1]); + dispatchPerformRedo(); + + // @todo enable/disable buttons + // updateButtonVisibility(); + } +}; + +export { + performSnapshot, + performUndo, + performRedo +};