Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,14 @@ class Runtime extends EventEmitter {
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.
* @const {string}
Expand Down Expand Up @@ -1547,6 +1555,7 @@ class Runtime extends EventEmitter {
this.stopAll();
this.targets.map(this.disposeTarget, this);
this._monitorState = OrderedMap({});
this.emit(Runtime.RUNTIME_DISPOSED);
// @todo clear out extensions? turboMode? etc.

// *********** Cloud *******************
Expand Down
1 change: 1 addition & 0 deletions src/extensions/scratch3_pen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Scratch3PenBlocks {
this._onTargetMoved = this._onTargetMoved.bind(this);

runtime.on('targetWasCreated', this._onTargetCreated);
runtime.on('RUNTIME_DISPOSED', this.clear.bind(this));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/unit/engine_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,14 @@ test('setCompatibilityMode does not restart if it was not running', t => {
t.equal(started, false);
t.end();
});

test('Disposing the runtime emits an event', t => {
let disposed = false;
const rt = new Runtime();
rt.addListener('RUNTIME_DISPOSED', () => {
disposed = true;
});
rt.dispose();
t.equal(disposed, true);
t.end();
});