1 Star 0 Fork 0

sam/scratch-gui

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
variable-utils.js 830 Bytes
一键复制 编辑 原始数据 按行查看 历史
Paul Kaplan 提交于 2018-12-19 23:54 +08:00 . Implement list import and export from files
// Utility functions for updating variables in the VM
// TODO (VM#1145) these should be moved to top-level VM API
const getVariable = (vm, targetId, variableId) => {
const target = targetId ?
vm.runtime.getTargetById(targetId) :
vm.runtime.getTargetForStage();
return target.variables[variableId];
};
const getVariableValue = (vm, targetId, variableId) => {
const variable = getVariable(vm, targetId, variableId);
// If array, return a new copy for mutating, ensuring that updates stay immutable.
if (variable.value instanceof Array) return variable.value.slice();
return variable.value;
};
const setVariableValue = (vm, targetId, variableId, value) => {
getVariable(vm, targetId, variableId).value = value;
};
export {
getVariable,
getVariableValue,
setVariableValue
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stduino/scratch-gui.git
git@gitee.com:stduino/scratch-gui.git
stduino
scratch-gui
scratch-gui
master

搜索帮助