diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 86525627d..ebe113f89 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -291,20 +291,20 @@ class Blocks { case 'checkbox': block.isMonitored = args.value; if (optRuntime && wasMonitored && !block.isMonitored) { - optRuntime.removeMonitor(block.id); + optRuntime.requestRemoveMonitor(block.id); } else if (optRuntime && !wasMonitored && block.isMonitored) { - optRuntime.addMonitor( + optRuntime.requestAddMonitor( // Ensure that value is not undefined, since React requires it { - // @todo(dd) this will collide if multiple sprites use same block + // @todo(vm#564) this will collide if multiple sprites use same block id: block.id, category: 'data', - // @todo(dd) how to handle translation here? + // @todo(vm#565) how to handle translation here? label: block.opcode, - // @todo(dd) for numerical values with decimals, some countries use comma + // @todo(vm#565) for numerical values with decimals, some countries use comma value: '', x: 0, - // @todo(dd) Don't require sending x and y when instantiating a + // @todo(vm#566) Don't require sending x and y when instantiating a // monitor. If it's not preset the GUI should decide. y: 0 } diff --git a/src/engine/execute.js b/src/engine/execute.js index 9fed7f43a..34e2e91be 100644 --- a/src/engine/execute.js +++ b/src/engine/execute.js @@ -97,7 +97,7 @@ const execute = function (sequencer, thread) { runtime.visualReport(currentBlockId, resolvedValue); } if (thread.updateMonitor) { - runtime.updateMonitor({ + runtime.requestUpdateMonitor({ id: currentBlockId, value: String(resolvedValue) }); diff --git a/src/engine/runtime.js b/src/engine/runtime.js index a6c2b5f8c..0ac3ccff2 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -246,22 +246,6 @@ class Runtime extends EventEmitter { return 'MONITORS_UPDATE'; } - /** - * Event name for monitors removed. - * @const {string} - */ - static get MONITORS_REMOVED () { - return 'MONITORS_REMOVED'; - } - - /** - * Event name for monitors added. - * @const {string} - */ - static get MONITORS_ADDED () { - return 'MONITORS_ADDED'; - } - /** * How rapidly we try to step threads by default, in ms. */ @@ -400,7 +384,7 @@ class Runtime extends EventEmitter { * @param {!Target} target Target to run thread on. * @param {?object} opts optional arguments * @param {?boolean} opts.showVisualReport true if the script should show speech bubble for its value - * @param {?boolean} opts.updateMonitor true if the script should show and update a monitor with its value + * @param {?boolean} opts.updateMonitor true if the script should update a monitor value * @return {!Thread} The newly created thread. */ _pushThread (id, target, opts) { @@ -468,7 +452,7 @@ class Runtime extends EventEmitter { * @param {?object} opts optional arguments to toggle script * @param {?string} opts.target target ID for target to run script on. If not supplied, uses editing target. * @param {?boolean} opts.showVisualReport true if the speech bubble should pop up on the block, false if not. - * @param {?boolean} opts.updateMonitor true if the monitor for this block should show and get updated. + * @param {?boolean} opts.updateMonitor true if the monitor for this block should get updated. */ toggleScript (topBlockId, opts) { opts = Object.assign({ @@ -702,6 +686,7 @@ class Runtime extends EventEmitter { // @todo: Only render when this.redrawRequested or clones rendered. this.renderer.draw(); } + // @todo only emit if monitors has changed since last time. this.emit(Runtime.MONITORS_UPDATE, Object.keys(this._monitorState).map(key => this._monitorState[key]) ); @@ -888,7 +873,7 @@ class Runtime extends EventEmitter { * overwrites it. * @param {!object} monitor Monitor to add. */ - addMonitor (monitor) { + requestAddMonitor (monitor) { this._monitorState[monitor.id] = monitor; } @@ -897,7 +882,7 @@ class Runtime extends EventEmitter { * exist in the state. * @param {!object} monitor Monitor to update. */ - updateMonitor (monitor) { + requestUpdateMonitor (monitor) { if (this._monitorState.hasOwnProperty(monitor.id)) { this._monitorState[monitor.id] = Object.assign({}, this._monitorState[monitor.id], monitor); } @@ -908,7 +893,7 @@ class Runtime extends EventEmitter { * not exist in the state. * @param {!object} monitorId ID of the monitor to remove. */ - removeMonitor (monitorId) { + requestRemoveMonitor (monitorId) { delete this._monitorState[monitorId]; } diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 241dcc9d2..9afa43cdc 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -58,12 +58,6 @@ class VirtualMachine extends EventEmitter { instance.runtime.on(Runtime.MONITORS_UPDATE, monitorList => { instance.emit(Runtime.MONITORS_UPDATE, monitorList); }); - instance.runtime.on(Runtime.MONITORS_REMOVED, monitorList => { - instance.emit(Runtime.MONITORS_REMOVED, monitorList); - }); - instance.runtime.on(Runtime.MONITORS_ADDED, monitorList => { - instance.emit(Runtime.MONITORS_ADDED, monitorList); - }); this.blockListener = this.blockListener.bind(this); this.flyoutBlockListener = this.flyoutBlockListener.bind(this);