Clear the pen layer when runtime dispose happens.

This commit is contained in:
Paul Kaplan 2018-12-04 16:43:31 -05:00
parent 122443a75f
commit 6bd2307c99
3 changed files with 21 additions and 0 deletions

View file

@ -626,6 +626,14 @@ class Runtime extends EventEmitter {
return 'RUNTIME_STARTED'; return 'RUNTIME_STARTED';
} }
/**
* Event name when the runtime dispose has been called.
* @const {string}
*/
static get RUNTIME_DISPOSED () {
return 'RUNTIME_DISPOSED';
}
/** /**
* Event name for reporting that a block was updated and needs to be rerendered. * Event name for reporting that a block was updated and needs to be rerendered.
* @const {string} * @const {string}
@ -1547,6 +1555,7 @@ class Runtime extends EventEmitter {
this.stopAll(); this.stopAll();
this.targets.map(this.disposeTarget, this); this.targets.map(this.disposeTarget, this);
this._monitorState = OrderedMap({}); this._monitorState = OrderedMap({});
this.emit(Runtime.RUNTIME_DISPOSED);
// @todo clear out extensions? turboMode? etc. // @todo clear out extensions? turboMode? etc.
// *********** Cloud ******************* // *********** Cloud *******************

View file

@ -67,6 +67,7 @@ class Scratch3PenBlocks {
this._onTargetMoved = this._onTargetMoved.bind(this); this._onTargetMoved = this._onTargetMoved.bind(this);
runtime.on('targetWasCreated', this._onTargetCreated); runtime.on('targetWasCreated', this._onTargetCreated);
runtime.on('RUNTIME_DISPOSED', this.clear.bind(this));
} }
/** /**

View file

@ -239,3 +239,14 @@ test('setCompatibilityMode does not restart if it was not running', t => {
t.equal(started, false); t.equal(started, false);
t.end(); t.end();
}); });
test('Disposing the runtime emits an event', t => {
let disposed = false;
const rt = new Runtime();
rt.addListener('RUNTIME_DISPOSED', () => {
disposed = true;
});
rt.start();
t.equal(disposed, true);
t.end();
});