From 79ab2fcb7281005a059d3e0e7ace3534e0323229 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 2 Aug 2018 10:00:21 -0400 Subject: [PATCH] Add turbo mode events --- src/engine/runtime.js | 16 ++++++++++++++++ src/virtual-machine.js | 5 +++++ test/unit/virtual-machine.js | 21 +++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 403768e0c..9a4ed3972 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -322,6 +322,22 @@ class Runtime extends EventEmitter { return 'BLOCK_GLOW_OFF'; } + /** + * Event name for turning on turbo mode. + * @const {string} + */ + static get TURBO_MODE_ON () { + return 'TURBO_MODE_ON'; + } + + /** + * Event name for turning off turbo mode. + * @const {string} + */ + static get TURBO_MODE_OFF () { + return 'TURBO_MODE_OFF'; + } + /** * Event name when the project is started (threads may not necessarily be * running). diff --git a/src/virtual-machine.js b/src/virtual-machine.js index a42bee1ad..b1b186972 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -148,6 +148,11 @@ class VirtualMachine extends EventEmitter { */ setTurboMode (turboModeOn) { this.runtime.turboMode = !!turboModeOn; + if (this.runtime.turboMode) { + this.emit(Runtime.TURBO_MODE_ON); + } else { + this.emit(Runtime.TURBO_MODE_OFF); + } } /** diff --git a/test/unit/virtual-machine.js b/test/unit/virtual-machine.js index 570a850e0..0310da046 100644 --- a/test/unit/virtual-machine.js +++ b/test/unit/virtual-machine.js @@ -857,3 +857,24 @@ test('shareBlocksToTarget chooses a fresh name for a new global variable checkin t.end(); }); + +test('Setting turbo mode emits events', t => { + let turboMode = null; + + const vm = new VirtualMachine(); + + vm.addListener('TURBO_MODE_ON', () => { + turboMode = true; + }); + vm.addListener('TURBO_MODE_OFF', () => { + turboMode = false; + }); + + vm.setTurboMode(true); + t.equal(turboMode, true); + + vm.setTurboMode(false); + t.equal(turboMode, false); + + t.end(); +});