Class: ConnectionChecker

Constructor

ConnectionChecker

new ConnectionChecker()

Class for connection type checking logic.

Implements
Blockly.IConnectionChecker

Methods

canConnect

public

canConnect(a, b, isDragging, opt_distance) returns boolean

Check whether the current connection can connect with the target connection.

Parameter

a

Blockly.Connection

Connection to check compatibility with.

b

Blockly.Connection

Connection to check compatibility with.

isDragging

boolean

True if the connection is being made by dragging a block.

opt_distance

Optional

number

The max allowable distance between the connections for drag checks.

Implements
Blockly.IConnectionChecker#canConnect
Returns

boolean Whether the connection is legal.

canConnectToPrevious_

protected

canConnectToPrevious_(a, b) returns boolean

Helper function for drag checking.

Parameter

a

Blockly.Connection

The connection to check, which must be a statement input or next connection.

Value must not be null.

b

Blockly.Connection

A nearby connection to check, which must be a previous connection.

Value must not be null.

Returns

boolean True if the connection is allowed, false otherwise.

canConnectWithReason

public

canConnectWithReason(a, b, isDragging, opt_distance) returns number

Checks whether the current connection can connect with the target connection, and return an error code if there are problems.

Parameter

a

Blockly.Connection

Connection to check compatibility with.

b

Blockly.Connection

Connection to check compatibility with.

isDragging

boolean

True if the connection is being made by dragging a block.

opt_distance

Optional

number

The max allowable distance between the connections for drag checks.

Implements
Blockly.IConnectionChecker#canConnectWithReason
Returns

number Blockly.Connection.CAN_CONNECT if the connection is legal, an error code otherwise.

doDragChecks

public

doDragChecks(a, b, distance) returns boolean

Check whether this connection can be made by dragging.

Parameter

a

Blockly.RenderedConnection

Connection to compare.

Value must not be null.

b

Blockly.RenderedConnection

Connection to compare against.

Value must not be null.

distance

number

The maximum allowable distance between connections.

Implements
Blockly.IConnectionChecker#doDragChecks
Returns

boolean True if the connection is allowed during a drag.

doSafetyChecks

public

doSafetyChecks(a, b) returns number

Check that connecting the given connections is safe, meaning that it would not break any of Blockly's basic assumptions (e.g. no self connections).

Parameter

a

Blockly.Connection

The first of the connections to check.

b

Blockly.Connection

The second of the connections to check.

Implements
Blockly.IConnectionChecker#doSafetyChecks
Returns

number An enum with the reason this connection is safe or unsafe.

doTypeChecks

public

doTypeChecks(a, b) returns boolean

Check whether this connection is compatible with another connection with respect to the value type system. E.g. square_root("Hello") is not compatible.

Parameter

a

Blockly.Connection

Connection to compare.

Value must not be null.

b

Blockly.Connection

Connection to compare against.

Value must not be null.

Implements
Blockly.IConnectionChecker#doTypeChecks
Returns

boolean True if the connections share a type.

getErrorMessage

public

getErrorMessage(errorCode, a, b) returns string

Helper method that translates a connection error code into a string.

Parameter

errorCode

number

The error code.

a

Blockly.Connection

One of the two connections being checked.

b

Blockly.Connection

The second of the two connections being checked.

Implements
Blockly.IConnectionChecker#getErrorMessage
Returns

string A developer-readable error string.