From 9032474c32497e6463d3bac324b97ac1d47b22d6 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Tue, 17 Dec 2019 13:37:09 -0700 Subject: [PATCH] Adding the ability to interrupt the Display's listeners, see https://github.com/phetsims/scenery/issues/218#issuecomment-316529669 --- js/display/Display.js | 18 ++++++++++++++++++ js/nodes/Node.js | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/js/display/Display.js b/js/display/Display.js index 799c27681..ebbf5d097 100644 --- a/js/display/Display.js +++ b/js/display/Display.js @@ -1141,6 +1141,24 @@ define( require => { }, get inputListeners() { return this.getInputListeners(); }, + /** + * Interrupts all input listeners that are attached to this Display. + * @public + * + * @returns {Display} - For chaining + */ + interruptInput: function() { + const listenersCopy = this.inputListeners; + + for ( let i = 0; i < listenersCopy.length; i++ ) { + const listener = listenersCopy[ i ]; + + listener.interrupt && listener.interrupt(); + } + + return this; + }, + ensureNotPainting: function() { assert && assert( !this._isPainting, 'This should not be run in the call tree of updateDisplay(). If you see this, it is likely that either the ' + diff --git a/js/nodes/Node.js b/js/nodes/Node.js index 53e9bb32b..657c6b1e7 100644 --- a/js/nodes/Node.js +++ b/js/nodes/Node.js @@ -1935,7 +1935,7 @@ define( require => { for ( let i = 0; i < listenersCopy.length; i++ ) { const listener = listenersCopy[ i ]; - listener.interrupt && listener.interrupt(); // TODO: get rid of the event? + listener.interrupt && listener.interrupt(); } return this;