Remove leftover instances of MONITORS_ADDED and MONITORS_REMOVED, change updateMonitor to requestUpdateMonitor, update some todos with tracking numbers.

This commit is contained in:
DD Liu 2017-05-15 10:12:25 -04:00
parent 7a1b3eccd0
commit 6ee1e6614c
4 changed files with 13 additions and 34 deletions

View file

@ -291,20 +291,20 @@ class Blocks {
case 'checkbox': case 'checkbox':
block.isMonitored = args.value; block.isMonitored = args.value;
if (optRuntime && wasMonitored && !block.isMonitored) { if (optRuntime && wasMonitored && !block.isMonitored) {
optRuntime.removeMonitor(block.id); optRuntime.requestRemoveMonitor(block.id);
} else if (optRuntime && !wasMonitored && block.isMonitored) { } else if (optRuntime && !wasMonitored && block.isMonitored) {
optRuntime.addMonitor( optRuntime.requestAddMonitor(
// Ensure that value is not undefined, since React requires it // 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, id: block.id,
category: 'data', category: 'data',
// @todo(dd) how to handle translation here? // @todo(vm#565) how to handle translation here?
label: block.opcode, 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: '', value: '',
x: 0, 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. // monitor. If it's not preset the GUI should decide.
y: 0 y: 0
} }

View file

@ -97,7 +97,7 @@ const execute = function (sequencer, thread) {
runtime.visualReport(currentBlockId, resolvedValue); runtime.visualReport(currentBlockId, resolvedValue);
} }
if (thread.updateMonitor) { if (thread.updateMonitor) {
runtime.updateMonitor({ runtime.requestUpdateMonitor({
id: currentBlockId, id: currentBlockId,
value: String(resolvedValue) value: String(resolvedValue)
}); });

View file

@ -246,22 +246,6 @@ class Runtime extends EventEmitter {
return 'MONITORS_UPDATE'; 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. * 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 {!Target} target Target to run thread on.
* @param {?object} opts optional arguments * @param {?object} opts optional arguments
* @param {?boolean} opts.showVisualReport true if the script should show speech bubble for its value * @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. * @return {!Thread} The newly created thread.
*/ */
_pushThread (id, target, opts) { _pushThread (id, target, opts) {
@ -468,7 +452,7 @@ class Runtime extends EventEmitter {
* @param {?object} opts optional arguments to toggle script * @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 {?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.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) { toggleScript (topBlockId, opts) {
opts = Object.assign({ opts = Object.assign({
@ -702,6 +686,7 @@ class Runtime extends EventEmitter {
// @todo: Only render when this.redrawRequested or clones rendered. // @todo: Only render when this.redrawRequested or clones rendered.
this.renderer.draw(); this.renderer.draw();
} }
// @todo only emit if monitors has changed since last time.
this.emit(Runtime.MONITORS_UPDATE, this.emit(Runtime.MONITORS_UPDATE,
Object.keys(this._monitorState).map(key => this._monitorState[key]) Object.keys(this._monitorState).map(key => this._monitorState[key])
); );
@ -888,7 +873,7 @@ class Runtime extends EventEmitter {
* overwrites it. * overwrites it.
* @param {!object} monitor Monitor to add. * @param {!object} monitor Monitor to add.
*/ */
addMonitor (monitor) { requestAddMonitor (monitor) {
this._monitorState[monitor.id] = monitor; this._monitorState[monitor.id] = monitor;
} }
@ -897,7 +882,7 @@ class Runtime extends EventEmitter {
* exist in the state. * exist in the state.
* @param {!object} monitor Monitor to update. * @param {!object} monitor Monitor to update.
*/ */
updateMonitor (monitor) { requestUpdateMonitor (monitor) {
if (this._monitorState.hasOwnProperty(monitor.id)) { if (this._monitorState.hasOwnProperty(monitor.id)) {
this._monitorState[monitor.id] = Object.assign({}, this._monitorState[monitor.id], monitor); this._monitorState[monitor.id] = Object.assign({}, this._monitorState[monitor.id], monitor);
} }
@ -908,7 +893,7 @@ class Runtime extends EventEmitter {
* not exist in the state. * not exist in the state.
* @param {!object} monitorId ID of the monitor to remove. * @param {!object} monitorId ID of the monitor to remove.
*/ */
removeMonitor (monitorId) { requestRemoveMonitor (monitorId) {
delete this._monitorState[monitorId]; delete this._monitorState[monitorId];
} }

View file

@ -58,12 +58,6 @@ class VirtualMachine extends EventEmitter {
instance.runtime.on(Runtime.MONITORS_UPDATE, monitorList => { instance.runtime.on(Runtime.MONITORS_UPDATE, monitorList => {
instance.emit(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.blockListener = this.blockListener.bind(this);
this.flyoutBlockListener = this.flyoutBlockListener.bind(this); this.flyoutBlockListener = this.flyoutBlockListener.bind(this);