Fixing radio import (#974)
This commit is contained in:
parent
efa92e6dee
commit
05aa56fe21
@ -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":
|
||||
node.setAttribute("type", "radio_on_number");
|
||||
node.removeChild(node.querySelector("field[name=receivedNumber]"));
|
||||
addField(node, renameMap, "receivedNumber");
|
||||
break;
|
||||
case "receivedString,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");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
node.removeChild(mutation);
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user