Merge pull request #1413 from paulkaplan/turbo-mode

Add turbo mode events
This commit is contained in:
Paul Kaplan 2018-08-02 10:15:40 -04:00 committed by GitHub
commit f38b96d70a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View file

@ -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).

View file

@ -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);
}
}
/**

View file

@ -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();
});