Fixing radio import (#974)

This commit is contained in:
Richard Knoll 2018-07-27 13:12:36 -07:00 committed by GitHub
parent efa92e6dee
commit 05aa56fe21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -502,26 +502,40 @@ namespace pxt.editor {
const mutation = node.querySelector("mutation");
if (!mutation) return;
const renameMap = JSON.parse(node.getAttribute("renamemap") || "{}");
switch (mutation.getAttribute("callbackproperties")) {
case "receivedNumber":
const props = mutation.getAttribute("callbackproperties");
if (props) {
const parts = props.split(",");
// It's tempting to generate radio_on_number if parts.length === 0 but
// that would create a variable named "receivedNumber" and possibly shadow
// an existing variable in the user's program. It's safer to stick to the
// old block.
if (parts.length === 1) {
if (parts[0] === "receivedNumber") {
node.setAttribute("type", "radio_on_number");
node.removeChild(node.querySelector("field[name=receivedNumber]"));
addField(node, renameMap, "receivedNumber");
break;
case "receivedString,receivedNumber":
}
else if (parts[0] === "receivedString") {
node.setAttribute("type", "radio_on_string");
node.removeChild(node.querySelector("field[name=receivedString]"));
addField(node, renameMap, "receivedString");
}
else {
return;
}
node.removeChild(mutation);
}
else if (parts.length === 2 && parts.indexOf("receivedNumber") !== -1 && parts.indexOf("receivedString") !== -1) {
node.setAttribute("type", "radio_on_value");
node.removeChild(node.querySelector("field[name=receivedNumber]"));
node.removeChild(node.querySelector("field[name=receivedString]"));
addField(node, renameMap, "name");
addField(node, renameMap, "value");
break;
case "receivedString":
node.setAttribute("type", "radio_on_string");
node.removeChild(node.querySelector("field[name=receivedString]"));
addField(node, renameMap, "receivedString");
break;
}
node.removeChild(mutation);
}
}
})
}