Skip to content

Commit

Permalink
Prevent 'c?a:b' block from performing type violations.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Mar 22, 2015
1 parent e571533 commit 706080c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,36 @@ Blockly.Blocks['logic_ternary'] = {
.appendField(Blockly.Msg.LOGIC_TERNARY_IF_FALSE);
this.setOutput(true);
this.setTooltip(Blockly.Msg.LOGIC_TERNARY_TOOLTIP);
this.prevParentConnection_ = null;
},
/**
* Called whenever anything on the workspace changes.
* Prevent mismatched types.
* @this Blockly.Block
*/
onchange: function() {
if (!this.workspace) {
// Block has been deleted.
return;
}
var blockA = this.getInputTargetBlock('THEN');
var blockB = this.getInputTargetBlock('ELSE');
var parentConnection = this.outputConnection.targetConnection;
// Kick blocks that existed prior to this change if they don't match.
if ((blockA || blockB) && parentConnection) {
for (var i = 0; i < 2; i++) {
var block = (i == 1) ? blockA : blockB;
if (block && !block.outputConnection.checkType_(parentConnection)) {
if (parentConnection === this.prevParentConnection_) {
this.setParent(null);
parentConnection.sourceBlock_.bumpNeighbours_();
} else {
block.setParent(null);
block.bumpNeighbours_();
}
}
}
}
this.prevParentConnection_ = parentConnection;
}
};
3 changes: 2 additions & 1 deletion blocks_compressed.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 706080c

Please sign in to comment.