Add a runtime event to track when the toolbox extension blocks need updating.

This commit is contained in:
Karishma Chadha 2019-04-24 11:28:02 -04:00
parent 91f0d59be0
commit 92a73fef55
2 changed files with 24 additions and 1 deletions

View file

@ -509,6 +509,14 @@ class Runtime extends EventEmitter {
return 'PROJECT_CHANGED';
}
/**
* Event name for report that a change was made that can be saved
* @const {string}
*/
static get TOOLBOX_EXTENSIONS_NEED_UPDATE () {
return 'TOOLBOX_EXTENSIONS_NEED_UPDATE';
}
/**
* Event name for targets update report.
* @const {string}
@ -1963,10 +1971,15 @@ class Runtime extends EventEmitter {
* @param {!Target} editingTarget New editing target.
*/
setEditingTarget (editingTarget) {
const oldEditingTarget = this._editingTarget;
this._editingTarget = editingTarget;
// Script glows must be cleared.
this._scriptGlowsPreviousFrame = [];
this._updateGlows();
if (oldEditingTarget !== this._editingTarget) {
this.requestToolboxExtensionsUpdate();
}
}
/**
@ -2384,12 +2397,19 @@ class Runtime extends EventEmitter {
}
/**
* Emit an event that indicate that the blocks on the workspace need updating.
* Emit an event that indicates that the blocks on the workspace need updating.
*/
requestBlocksUpdate () {
this.emit(Runtime.BLOCKS_NEED_UPDATE);
}
/**
* Emit an event that indicates that the toolbox extension blocks need updating.
*/
requestToolboxExtensionsUpdate () {
this.emit(Runtime.TOOLBOX_EXTENSIONS_NEED_UPDATE);
}
/**
* Set up timers to repeatedly step in a browser.
*/

View file

@ -121,6 +121,9 @@ class VirtualMachine extends EventEmitter {
this.runtime.on(Runtime.BLOCKS_NEED_UPDATE, () => {
this.emitWorkspaceUpdate();
});
this.runtime.on(Runtime.TOOLBOX_EXTENSIONS_NEED_UPDATE, () => {
this.extensionManager.refreshBlocks();
});
this.runtime.on(Runtime.PERIPHERAL_LIST_UPDATE, info => {
this.emit(Runtime.PERIPHERAL_LIST_UPDATE, info);
});