Add history.pauseChangeDispatch / history.resumeChangeDispatch

To avoid dispatching change events at improper times
This commit is contained in:
Bryan Housel
2019-03-05 17:46:54 -05:00
parent e9628848c0
commit 0ea69548ea
2 changed files with 57 additions and 17 deletions
+20 -5
View File
@@ -36,6 +36,7 @@ export function coreHistory(context) {
var duration = 150;
var _imageryUsed = [];
var _checkpoints = {};
var _pausedGraph;
var _stack;
var _index;
var _tree;
@@ -104,11 +105,13 @@ export function coreHistory(context) {
// determine difference and dispatch a change event
function change(previous, isAnnotated) {
var difference = coreDifference(previous, history.graph());
dispatch.call('change', this, difference);
if (isAnnotated) {
// actions like dragging a node can fire lots of changes,
// so use 'annotatedChange' to listen for grouped undo/redo changes
dispatch.call('annotatedChange', this, difference);
if (!_pausedGraph) {
dispatch.call('change', this, difference);
if (isAnnotated) {
// actions like dragging a node can fire lots of changes,
// so use 'annotatedChange' to listen for grouped undo/redo changes
dispatch.call('annotatedChange', this, difference);
}
}
return difference;
}
@@ -244,6 +247,18 @@ export function coreHistory(context) {
},
pauseChangeDispatch: function() {
_pausedGraph = _stack[_index].graph;
},
resumeChangeDispatch: function() {
var previous = _pausedGraph;
_pausedGraph = null;
return change(previous, true);
},
undoAnnotation: function() {
var i = _index;
while (i >= 0) {