Fix warnings related to connections. (#3306)

* Fix warnings related to connections.
This commit is contained in:
Sam El-Husseini
2019-10-23 17:56:52 -04:00
committed by GitHub
parent 83e7ebb228
commit 52bef4463c
11 changed files with 132 additions and 116 deletions

View File

@@ -554,7 +554,7 @@ Blockly.Constants.Logic.LOGIC_COMPARE_ONCHANGE_MIXIN = {
var blockB = this.getInputTargetBlock('B');
// Disconnect blocks that existed prior to this change if they don't match.
if (blockA && blockB &&
!blockA.outputConnection.checkType_(blockB.outputConnection)) {
!blockA.outputConnection.checkType(blockB.outputConnection)) {
// Mismatch between two inputs. Revert the block connections,
// bumping away the newly connected block(s).
Blockly.Events.setGroup(e.group);
@@ -621,7 +621,7 @@ Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN = {
if ((blockA || blockB) && parentConnection) {
for (var i = 0; i < 2; i++) {
var block = (i == 1) ? blockA : blockB;
if (block && !block.outputConnection.checkType_(parentConnection)) {
if (block && !block.outputConnection.checkType(parentConnection)) {
// Ensure that any disconnections are grouped with the causing event.
Blockly.Events.setGroup(e.group);
if (parentConnection === this.prevParentConnection_) {

View File

@@ -441,7 +441,7 @@ Blockly.Block.prototype.unplugFromRow_ = function(opt_healStack) {
// Disconnect the child block.
childConnection.disconnect();
// Connect child to the parent if possible, otherwise bump away.
if (childConnection.checkType_(parentConnection)) {
if (childConnection.checkType(parentConnection)) {
parentConnection.connect(childConnection);
} else {
childConnection.onFailedConnect(parentConnection);
@@ -493,7 +493,7 @@ Blockly.Block.prototype.unplugFromStack_ = function(opt_healStack) {
// Disconnect the next statement.
var nextTarget = this.nextConnection.targetConnection;
nextTarget.disconnect();
if (previousTarget && previousTarget.checkType_(nextTarget)) {
if (previousTarget && previousTarget.checkType(nextTarget)) {
// Attach the next statement to the previous statement.
previousTarget.connect(nextTarget);
}
@@ -1880,7 +1880,7 @@ Blockly.Block.prototype.moveBy = function(dx, dy) {
* Create a connection of the specified type.
* @param {number} type The type of the connection to create.
* @return {!Blockly.Connection} A new connection of the specified type.
* @private
* @protected
*/
Blockly.Block.prototype.makeConnection_ = function(type) {
return new Blockly.Connection(this, type);

View File

@@ -243,7 +243,7 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
var deleted = this.maybeDeleteBlock_();
if (!deleted) {
// These are expensive and don't need to be done if we're deleting.
this.draggingBlock_.moveConnections_(delta.x, delta.y);
this.draggingBlock_.moveConnections(delta.x, delta.y);
this.draggingBlock_.setDragging(false);
this.fireMoveEvent_();
if (this.draggedConnectionManager_.wouldConnectBlock()) {

View File

@@ -398,7 +398,7 @@ Blockly.BlockSvg.prototype.setParent = function(newParent) {
newParent.getSvgRoot().appendChild(svgRoot);
var newXY = this.getRelativeToSurfaceXY();
// Move the connections to match the child's new position.
this.moveConnections_(newXY.x - oldXY.x, newXY.y - oldXY.y);
this.moveConnections(newXY.x - oldXY.x, newXY.y - oldXY.y);
}
// If we are losing a parent, we want to move our DOM element to the
// root of the workspace.
@@ -462,7 +462,7 @@ Blockly.BlockSvg.prototype.moveBy = function(dx, dy) {
}
var xy = this.getRelativeToSurfaceXY();
this.translate(xy.x + dx, xy.y + dy);
this.moveConnections_(dx, dy);
this.moveConnections(dx, dy);
if (eventsEnabled) {
event.recordNew();
Blockly.Events.fire(event);
@@ -886,9 +886,9 @@ Blockly.BlockSvg.prototype.showContextMenu = function(e) {
* units.
* @param {number} dy Vertical offset from current location, in workspace
* units.
* @private
* @package
*/
Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
Blockly.BlockSvg.prototype.moveConnections = function(dx, dy) {
if (!this.rendered) {
// Rendering is required to lay out the blocks.
// This is probably an invisible block attached to a collapsed block.
@@ -905,7 +905,7 @@ Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
// Recurse through all blocks attached under this one.
for (var i = 0; i < this.childBlocks_.length; i++) {
this.childBlocks_[i].moveConnections_(dx, dy);
this.childBlocks_[i].moveConnections(dx, dy);
}
};
@@ -1586,7 +1586,7 @@ Blockly.BlockSvg.prototype.startTrackingConnections = function() {
* @param {boolean} all If true, return all connections even hidden ones.
* Otherwise, for a non-rendered block return an empty list, and for a
* collapsed block don't return inputs connections.
* @return {!Array.<!Blockly.Connection>} Array of connections.
* @return {!Array.<!Blockly.RenderedConnection>} Array of connections.
* @package
*/
Blockly.BlockSvg.prototype.getConnections_ = function(all) {
@@ -1645,7 +1645,7 @@ Blockly.BlockSvg.prototype.getMatchingConnection = function(otherBlock, conn) {
* Create a connection of the specified type.
* @param {number} type The type of the connection to create.
* @return {!Blockly.RenderedConnection} A new connection of the specified type.
* @private
* @protected
*/
Blockly.BlockSvg.prototype.makeConnection_ = function(type) {
return new Blockly.RenderedConnection(this, type);
@@ -1675,7 +1675,7 @@ Blockly.BlockSvg.prototype.bumpNeighbours = function() {
connection.targetBlock().bumpNeighbours();
}
var neighbours = connection.neighbours_(Blockly.SNAP_RADIUS);
var neighbours = connection.neighbours(Blockly.SNAP_RADIUS);
for (var j = 0, otherConnection; otherConnection = neighbours[j]; j++) {
// If both connections are connected, that's probably fine. But if
@@ -1686,9 +1686,9 @@ Blockly.BlockSvg.prototype.bumpNeighbours = function() {
// Always bump the inferior block.
if (connection.isSuperior()) {
otherConnection.bumpAwayFrom_(connection);
otherConnection.bumpAwayFrom(connection);
} else {
connection.bumpAwayFrom_(otherConnection);
connection.bumpAwayFrom(otherConnection);
}
}
}
@@ -1735,8 +1735,8 @@ Blockly.BlockSvg.prototype.positionNearConnection = function(sourceConnection,
// otherwise its position is set by the previous block.
if (sourceConnection.type == Blockly.NEXT_STATEMENT ||
sourceConnection.type == Blockly.INPUT_VALUE) {
var dx = targetConnection.x_ - sourceConnection.x_;
var dy = targetConnection.y_ - sourceConnection.y_;
var dx = targetConnection.x - sourceConnection.x;
var dy = targetConnection.y - sourceConnection.y;
this.moveBy(dx, dy);
}
@@ -1817,7 +1817,7 @@ Blockly.BlockSvg.prototype.updateConnectionLocations_ = function() {
if (conn) {
conn.moveToOffset(blockTL);
if (conn.isConnected()) {
conn.tighten_();
conn.tighten();
}
}
}
@@ -1825,7 +1825,7 @@ Blockly.BlockSvg.prototype.updateConnectionLocations_ = function() {
if (this.nextConnection) {
this.nextConnection.moveToOffset(blockTL);
if (this.nextConnection.isConnected()) {
this.nextConnection.tighten_();
this.nextConnection.tighten();
}
}
};

View File

@@ -85,16 +85,16 @@ Blockly.Connection.prototype.shadowDom_ = null;
/**
* Horizontal location of this connection.
* @type {number}
* @protected
* @package
*/
Blockly.Connection.prototype.x_ = 0;
Blockly.Connection.prototype.x = 0;
/**
* Vertical location of this connection.
* @type {number}
* @protected
* @package
*/
Blockly.Connection.prototype.y_ = 0;
Blockly.Connection.prototype.y = 0;
/**
* Connect two connections together. This is the connection on the superior
@@ -132,7 +132,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
// Attempt to reattach the orphan at the end of the newly inserted
// block. Since this block may be a row, walk down to the end
// or to the first (and only) shadow block.
var connection = Blockly.Connection.lastConnectionInRow_(
var connection = Blockly.Connection.lastConnectionInRow(
childBlock, orphanBlock);
if (connection) {
orphanBlock.outputConnection.connect(connection);
@@ -153,7 +153,7 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
if (nextBlock && !nextBlock.isShadow()) {
newBlock = nextBlock;
} else {
if (orphanBlock.previousConnection.checkType_(
if (orphanBlock.previousConnection.checkType(
newBlock.nextConnection)) {
newBlock.nextConnection.connect(orphanBlock.previousConnection);
orphanBlock = null;
@@ -272,7 +272,7 @@ Blockly.Connection.prototype.canConnectWithReason = function(target) {
return Blockly.Connection.REASON_WRONG_TYPE;
} else if (blockA && blockB && blockA.workspace !== blockB.workspace) {
return Blockly.Connection.REASON_DIFFERENT_WORKSPACES;
} else if (!this.checkType_(target)) {
} else if (!this.checkType(target)) {
return Blockly.Connection.REASON_CHECKS_FAILED;
} else if (blockA.isShadow() && !blockB.isShadow()) {
return Blockly.Connection.REASON_SHADOW_PARENT;
@@ -414,7 +414,7 @@ Blockly.Connection.prototype.isConnectionAllowed = function(candidate) {
/**
* Behavior after a connection attempt fails.
* @param {Blockly.Connection} _otherConnection Connection that this connection
* @param {!Blockly.Connection} _otherConnection Connection that this connection
* failed to connect to.
* @package
*/
@@ -473,11 +473,11 @@ Blockly.Connection.connectReciprocally_ = function(first, second) {
* @private
*/
Blockly.Connection.singleConnection_ = function(block, orphanBlock) {
var connection = false;
var connection = null;
for (var i = 0; i < block.inputList.length; i++) {
var thisConnection = block.inputList[i].connection;
if (thisConnection && thisConnection.type == Blockly.INPUT_VALUE &&
orphanBlock.outputConnection.checkType_(thisConnection)) {
orphanBlock.outputConnection.checkType(thisConnection)) {
if (connection) {
return null; // More than one connection.
}
@@ -497,9 +497,9 @@ Blockly.Connection.singleConnection_ = function(block, orphanBlock) {
* @param {!Blockly.Block} orphanBlock The block that is looking for a home.
* @return {Blockly.Connection} The suitable connection point on the chain
* of blocks, or null.
* @private
* @package
*/
Blockly.Connection.lastConnectionInRow_ = function(startBlock, orphanBlock) {
Blockly.Connection.lastConnectionInRow = function(startBlock, orphanBlock) {
var newBlock = startBlock;
var connection;
while (connection = Blockly.Connection.singleConnection_(
@@ -606,9 +606,9 @@ Blockly.Connection.prototype.targetBlock = function() {
* value type system. E.g. square_root("Hello") is not compatible.
* @param {!Blockly.Connection} otherConnection Connection to compare against.
* @return {boolean} True if the connections share a type.
* @protected
* @package
*/
Blockly.Connection.prototype.checkType_ = function(otherConnection) {
Blockly.Connection.prototype.checkType = function(otherConnection) {
if (!this.check_ || !otherConnection.check_) {
// One or both sides are promiscuous enough that anything will fit.
return true;
@@ -624,12 +624,27 @@ Blockly.Connection.prototype.checkType_ = function(otherConnection) {
};
/**
* Function to be called when this connection's compatible types have changed.
* Is this connection compatible with another connection with respect to the
* value type system. E.g. square_root("Hello") is not compatible.
* @param {!Blockly.Connection} otherConnection Connection to compare against.
* @return {boolean} True if the connections share a type.
* @private
* @deprecated October 2019, use connection.checkType instead.
*/
Blockly.Connection.prototype.checkType_ = function(otherConnection) {
console.warn('Deprecated call to Blockly.Connection.prototype.checkType_, ' +
'use Blockly.Connection.prototype.checkType instead.');
return this.checkType(otherConnection);
};
/**
* Function to be called when this connection's compatible types have changed.
* @protected
*/
Blockly.Connection.prototype.onCheckChanged_ = function() {
// The new value type may not be compatible with the existing connection.
if (this.isConnected() && !this.checkType_(this.targetConnection)) {
if (this.isConnected() && (!this.targetConnection ||
!this.checkType(this.targetConnection))) {
var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
child.unplug();
}
@@ -637,8 +652,8 @@ Blockly.Connection.prototype.onCheckChanged_ = function() {
/**
* Change a connection's compatibility.
* @param {string|!Array<string>} check Compatible value type or list of value
* types. Null if all types are compatible.
* @param {?(string|!Array<string>)} check Compatible value type or list of
* value types. Null if all types are compatible.
* @return {!Blockly.Connection} The connection being modified
* (to allow chaining).
*/
@@ -692,9 +707,9 @@ Blockly.Connection.prototype.getShadowDom = function() {
* computed from the rendered positioning.
* @param {number} _maxLimit The maximum radius to another connection.
* @return {!Array.<!Blockly.Connection>} List of connections.
* @private
* @package
*/
Blockly.Connection.prototype.neighbours_ = function(_maxLimit) {
Blockly.Connection.prototype.neighbours = function(_maxLimit) {
return [];
};

View File

@@ -77,11 +77,11 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) {
return -1;
}
var yPos = conn.y_;
yPos = conn.y;
// Walk forward and back on the y axis looking for the connection.
var pointerMin = bestGuess;
var pointerMax = bestGuess;
while (pointerMin >= 0 && this.connections_[pointerMin].y_ == yPos) {
while (pointerMin >= 0 && this.connections_[pointerMin].y == yPos) {
if (this.connections_[pointerMin] == conn) {
return pointerMin;
}
@@ -89,7 +89,7 @@ Blockly.ConnectionDB.prototype.findIndexOfConnection_ = function(conn, yPos) {
}
while (pointerMax < this.connections_.length &&
this.connections_[pointerMax].y_ == yPos) {
this.connections_[pointerMax].y == yPos) {
if (this.connections_[pointerMax] == conn) {
return pointerMax;
}
@@ -113,9 +113,9 @@ Blockly.ConnectionDB.prototype.calculateIndexForYPos_ = function(yPos) {
var pointerMax = this.connections_.length;
while (pointerMin < pointerMax) {
var pointerMid = Math.floor((pointerMin + pointerMax) / 2);
if (this.connections_[pointerMid].y_ < yPos) {
if (this.connections_[pointerMid].y < yPos) {
pointerMin = pointerMid + 1;
} else if (this.connections_[pointerMid].y_ > yPos) {
} else if (this.connections_[pointerMid].y > yPos) {
pointerMax = pointerMid;
} else {
pointerMin = pointerMid;
@@ -149,15 +149,15 @@ Blockly.ConnectionDB.prototype.removeConnection = function(connection, yPos) {
*/
Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) {
var db = this.connections_;
var currentX = connection.x_;
var currentY = connection.y_;
var currentX = connection.x;
var currentY = connection.y;
// Binary search to find the closest y location.
var pointerMin = 0;
var pointerMax = db.length - 2;
var pointerMid = pointerMax;
while (pointerMin < pointerMid) {
if (db[pointerMid].y_ < currentY) {
if (db[pointerMid].y < currentY) {
pointerMin = pointerMid;
} else {
pointerMax = pointerMid;
@@ -175,8 +175,8 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) {
* the other connection is less than the allowed radius.
*/
function checkConnection_(yIndex) {
var dx = currentX - db[yIndex].x_;
var dy = currentY - db[yIndex].y_;
var dx = currentX - db[yIndex].x;
var dy = currentY - db[yIndex].y;
var r = Math.sqrt(dx * dx + dy * dy);
if (r <= maxRadius) {
neighbours.push(db[yIndex]);
@@ -209,7 +209,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) {
* @private
*/
Blockly.ConnectionDB.prototype.isInYRange_ = function(index, baseY, maxRadius) {
return (Math.abs(this.connections_[index].y_ - baseY) <= maxRadius);
return (Math.abs(this.connections_[index].y - baseY) <= maxRadius);
};
/**
@@ -232,16 +232,16 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
}
// Stash the values of x and y from before the drag.
var baseY = conn.y_;
var baseX = conn.x_;
var baseY = conn.y;
var baseX = conn.x;
conn.x_ = baseX + dxy.x;
conn.y_ = baseY + dxy.y;
conn.x = baseX + dxy.x;
conn.y = baseY + dxy.y;
// calculateIndexForYPos_ finds an index for insertion, which is always
// after any block with the same y index. We want to search both forward
// and back, so search on both sides of the index.
var closestIndex = this.calculateIndexForYPos_(conn.y_);
var closestIndex = this.calculateIndexForYPos_(conn.y);
var bestConnection = null;
var bestRadius = maxRadius;
@@ -249,7 +249,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
// Walk forward and back on the y axis looking for the closest x,y point.
var pointerMin = closestIndex - 1;
while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y_, maxRadius)) {
while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y, maxRadius)) {
temp = this.connections_[pointerMin];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
@@ -260,7 +260,7 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
var pointerMax = closestIndex;
while (pointerMax < this.connections_.length &&
this.isInYRange_(pointerMax, conn.y_, maxRadius)) {
this.isInYRange_(pointerMax, conn.y, maxRadius)) {
temp = this.connections_[pointerMax];
if (conn.isConnectionAllowed(temp, bestRadius)) {
bestConnection = temp;
@@ -270,8 +270,8 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
}
// Reset the values of x and y.
conn.x_ = baseX;
conn.y_ = baseY;
conn.x = baseX;
conn.y = baseY;
// If there were no valid connections, bestConnection will be null.
return {connection: bestConnection, radius: bestRadius};

View File

@@ -324,8 +324,8 @@ Blockly.InsertionMarkerManager.prototype.shouldUpdatePreviews_ = function(
this.localConnection_ == candidateLocal) {
return false;
}
var xDiff = this.localConnection_.x_ + dxy.x - this.closestConnection_.x_;
var yDiff = this.localConnection_.y_ + dxy.y - this.closestConnection_.y_;
var xDiff = this.localConnection_.x + dxy.x - this.closestConnection_.x;
var yDiff = this.localConnection_.y + dxy.y - this.closestConnection_.y;
var curDistance = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
// Slightly prefer the existing preview over a new preview.
return !(candidateClosest && radius > curDistance -
@@ -409,7 +409,7 @@ Blockly.InsertionMarkerManager.prototype.shouldReplace_ = function() {
if (local.type == Blockly.OUTPUT_VALUE) {
// Insert the dragged block into the stack if possible.
if (!closest.isConnected() ||
Blockly.Connection.lastConnectionInRow_(this.topBlock_,
Blockly.Connection.lastConnectionInRow(this.topBlock_,
closest.targetConnection.getSourceBlock())) {
return false; // Insert.
}

View File

@@ -548,7 +548,7 @@ Blockly.navigation.disconnectBlocks_ = function() {
return;
}
superiorConnection.disconnect();
inferiorConnection.bumpAwayFrom_(superiorConnection);
inferiorConnection.bumpAwayFrom(superiorConnection);
var rootBlock = superiorConnection.getSourceBlock().getRootBlock();
rootBlock.bringToFront();

View File

@@ -82,7 +82,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection);
Blockly.RenderedConnection.prototype.dispose = function() {
Blockly.RenderedConnection.superClass_.dispose.call(this);
if (this.tracked_) {
this.db_.removeConnection(this, this.y_);
this.db_.removeConnection(this, this.y);
}
};
@@ -114,8 +114,8 @@ Blockly.RenderedConnection.prototype.targetBlock = function() {
* @return {number} The distance between connections, in workspace units.
*/
Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) {
var xDiff = this.x_ - otherConnection.x_;
var yDiff = this.y_ - otherConnection.y_;
var xDiff = this.x - otherConnection.x;
var yDiff = this.y - otherConnection.y;
return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
};
@@ -124,9 +124,9 @@ Blockly.RenderedConnection.prototype.distanceFrom = function(otherConnection) {
* visually interfere with the specified connection.
* @param {!Blockly.Connection} staticConnection The connection to move away
* from.
* @private
* @package
*/
Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection) {
Blockly.RenderedConnection.prototype.bumpAwayFrom = function(staticConnection) {
if (this.sourceBlock_.workspace.isDragging()) {
// Don't move blocks around while the user is doing the same.
return;
@@ -152,17 +152,17 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection)
// Raise it to the top for extra visibility.
var selected = Blockly.selected == rootBlock;
selected || rootBlock.addSelect();
var dx = (staticConnection.x_ + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x_;
var dy = (staticConnection.y_ + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y_;
var dx = (staticConnection.x + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x;
var dy = (staticConnection.y + Blockly.SNAP_RADIUS +
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.y;
if (reverse) {
// When reversing a bump due to an uneditable block, bump up.
dy = -dy;
}
if (rootBlock.RTL) {
dx = (staticConnection.x_ - Blockly.SNAP_RADIUS -
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x_;
dx = (staticConnection.x - Blockly.SNAP_RADIUS -
Math.floor(Math.random() * Blockly.BUMP_RANDOMNESS)) - this.x;
}
rootBlock.moveBy(dx, dy);
selected || rootBlock.removeSelect();
@@ -175,11 +175,11 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection)
*/
Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
if (this.tracked_) {
this.db_.removeConnection(this, this.y_);
this.db_.removeConnection(this, this.y);
this.db_.addConnection(this, y);
}
this.x_ = x;
this.y_ = y;
this.x = x;
this.y = y;
};
/**
@@ -188,7 +188,7 @@ Blockly.RenderedConnection.prototype.moveTo = function(x, y) {
* @param {number} dy Change to y coordinate, in workspace units.
*/
Blockly.RenderedConnection.prototype.moveBy = function(dx, dy) {
this.moveTo(this.x_ + dx, this.y_ + dy);
this.moveTo(this.x + dx, this.y + dy);
};
/**
@@ -223,11 +223,11 @@ Blockly.RenderedConnection.prototype.getOffsetInBlock = function() {
/**
* Move the blocks on either side of this connection right next to each other.
* @private
* @package
*/
Blockly.RenderedConnection.prototype.tighten_ = function() {
var dx = this.targetConnection.x_ - this.x_;
var dy = this.targetConnection.y_ - this.y_;
Blockly.RenderedConnection.prototype.tighten = function() {
var dx = this.targetConnection.x - this.x;
var dy = this.targetConnection.y - this.y;
if (dx != 0 || dy != 0) {
var block = this.targetBlock();
var svgRoot = block.getSvgRoot();
@@ -238,7 +238,7 @@ Blockly.RenderedConnection.prototype.tighten_ = function() {
var xy = Blockly.utils.getRelativeXY(svgRoot);
block.getSvgRoot().setAttribute('transform',
'translate(' + (xy.x - dx) + ',' + (xy.y - dy) + ')');
block.moveConnections_(-dx, -dy);
block.moveConnections(-dx, -dy);
}
};
@@ -280,8 +280,8 @@ Blockly.RenderedConnection.prototype.highlight = function() {
Blockly.utils.svgPaths.lineOnAxis('h', xLen);
}
var xy = this.sourceBlock_.getRelativeToSurfaceXY();
var x = this.x_ - xy.x;
var y = this.y_ - xy.y;
var x = this.x - xy.x;
var y = this.y - xy.y;
Blockly.Connection.highlightedPath_ = Blockly.utils.dom.createSvgElement(
'path',
{
@@ -315,9 +315,9 @@ Blockly.RenderedConnection.prototype.setTracking = function(doTracking) {
return;
}
if (doTracking) {
this.db_.addConnection(this, this.y_);
this.db_.addConnection(this, this.y);
} else {
this.db_.removeConnection(this, this.y_);
this.db_.removeConnection(this, this.y);
}
this.tracked_ = doTracking;
};
@@ -409,13 +409,13 @@ Blockly.RenderedConnection.prototype.isConnectionAllowed = function(candidate,
/**
* Behavior after a connection attempt fails.
* @param {Blockly.Connection} otherConnection Connection that this connection
* @param {!Blockly.Connection} otherConnection Connection that this connection
* failed to connect to.
* @package
*/
Blockly.RenderedConnection.prototype.onFailedConnect = function(
otherConnection) {
this.bumpAwayFrom_(otherConnection);
this.bumpAwayFrom(otherConnection);
};
@@ -468,9 +468,9 @@ Blockly.RenderedConnection.prototype.respawnShadow_ = function() {
* @param {number} maxLimit The maximum radius to another connection, in
* workspace units.
* @return {!Array.<!Blockly.Connection>} List of connections.
* @private
* @package
*/
Blockly.RenderedConnection.prototype.neighbours_ = function(maxLimit) {
Blockly.RenderedConnection.prototype.neighbours = function(maxLimit) {
return this.dbOpposite_.getNeighbours(this, maxLimit);
};
@@ -478,7 +478,7 @@ Blockly.RenderedConnection.prototype.neighbours_ = function(maxLimit) {
* Connect two connections together. This is the connection on the superior
* block. Rerender blocks as needed.
* @param {!Blockly.Connection} childConnection Connection on inferior block.
* @private
* @protected
*/
Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
Blockly.RenderedConnection.superClass_.connect_.call(this, childConnection);
@@ -509,11 +509,12 @@ Blockly.RenderedConnection.prototype.connect_ = function(childConnection) {
/**
* Function to be called when this connection's compatible types have changed.
* @private
* @protected
*/
Blockly.RenderedConnection.prototype.onCheckChanged_ = function() {
// The new value type may not be compatible with the existing connection.
if (this.isConnected() && !this.checkType_(this.targetConnection)) {
if (this.isConnected() && (!this.targetConnection ||
!this.checkType(this.targetConnection))) {
var child = this.isSuperior() ? this.targetBlock() : this.sourceBlock_;
child.unplug();
// Bump away.

View File

@@ -22,8 +22,8 @@ suite('Connection Database', function() {
this.assertOrder = function() {
var length = this.database.connections_.length;
for (var i = 1; i < length; i++) {
chai.assert.isAtMost(this.database.connections_[i - 1].y_,
this.database.connections_[i].y_);
chai.assert.isAtMost(this.database.connections_[i - 1].y,
this.database.connections_[i].y);
}
};
this.createConnection = function(x, y, type, opt_database) {
@@ -33,8 +33,8 @@ suite('Connection Database', function() {
workspace.connectionDBList[type] = opt_database || this.database;
var connection = new Blockly.RenderedConnection(
{workspace: workspace}, type);
connection.x_ = x;
connection.y_ = y;
connection.x = x;
connection.y = y;
return connection;
};
this.createSimpleTestConnections = function() {
@@ -45,11 +45,11 @@ suite('Connection Database', function() {
};
});
test('Add Connection', function() {
var y2 = {y_: 2};
var y4 = {y_: 4};
var y1 = {y_: 1};
var y3a = {y_: 3};
var y3b = {y_: 3};
var y2 = {y: 2};
var y4 = {y: 4};
var y1 = {y: 1};
var y3a = {y: 3};
var y3b = {y: 3};
this.database.addConnection(y2, 2);
chai.assert.sameOrderedMembers(
@@ -73,12 +73,12 @@ suite('Connection Database', function() {
});
test('Remove Connection', function() {
var y2 = {y_: 2};
var y4 = {y_: 4};
var y1 = {y_: 1};
var y3a = {y_: 3};
var y3b = {y_: 3};
var y3c = {y_: 3};
var y2 = {y: 2};
var y4 = {y: 4};
var y1 = {y: 1};
var y3a = {y: 3};
var y3b = {y: 3};
var y3c = {y: 3};
this.database.addConnection(y2, 2);
this.database.addConnection(y4, 4);

View File

@@ -168,31 +168,31 @@ suite('Connections', function() {
this.con2 = new Blockly.Connection({}, Blockly.NEXT_STATEMENT);
});
test('No Types', function() {
chai.assert.isTrue(this.con1.checkType_(this.con2));
chai.assert.isTrue(this.con1.checkType((this.con2)));
});
test('Same Type', function() {
this.con1.setCheck('type1');
this.con2.setCheck('type1');
chai.assert.isTrue(this.con1.checkType_(this.con2));
chai.assert.isTrue(this.con1.checkType((this.con2)));
});
test('Same Types', function() {
this.con1.setCheck(['type1', 'type2']);
this.con2.setCheck(['type1', 'type2']);
chai.assert.isTrue(this.con1.checkType_(this.con2));
chai.assert.isTrue(this.con1.checkType((this.con2)));
});
test('Single Same Type', function() {
this.con1.setCheck(['type1', 'type2']);
this.con2.setCheck(['type1', 'type3']);
chai.assert.isTrue(this.con1.checkType_(this.con2));
chai.assert.isTrue(this.con1.checkType((this.con2)));
});
test('One Typed, One Promiscuous', function() {
this.con1.setCheck('type1');
chai.assert.isTrue(this.con1.checkType_(this.con2));
chai.assert.isTrue(this.con1.checkType((this.con2)));
});
test('No Compatible Types', function() {
this.con1.setCheck('type1');
this.con2.setCheck('type2');
chai.assert.isFalse(this.con1.checkType_(this.con2));
chai.assert.isFalse(this.con1.checkType((this.con2)));
});
});
});