support rename variable

This commit is contained in:
DD Liu 2017-07-10 18:29:25 -04:00
parent 6fa49b1e7a
commit 7f1f9079e3
2 changed files with 14 additions and 1 deletions

View file

@ -4,6 +4,7 @@ const Blocks = require('./blocks');
const Variable = require('../engine/variable');
const List = require('../engine/list');
const uid = require('../util/uid');
const {Map} = require('immutable');
/**
* @fileoverview
@ -161,6 +162,17 @@ class Target extends EventEmitter {
const variable = this.variables[id];
if (variable.id === id) {
variable.name = newName;
const blocks = this.runtime.monitorBlocks;
blocks.changeBlock({
id: id,
element: 'field',
name: 'VARIABLE',
value: newName
}, this.runtime);
this.runtime.requestUpdateMonitor(Map({
id: id,
params: blocks._getBlockParams(blocks.getBlock(variable.id))
}));
}
}
}
@ -172,6 +184,7 @@ class Target extends EventEmitter {
deleteVariable (id) {
if (this.variables.hasOwnProperty(id)) {
delete this.variables[id];
this.runtime.requestRemoveMonitor(id);
}
}