Skip to main content

Class: ConnectionChecker

Defined in: packages/blockly/core/connection_checker.ts:26

Class for connection type checking logic.

Implements

Methods index

MethodDescription
canConnectCheck whether the current connection can connect with the target connection.
canConnectWithReasonChecks whether the current connection can connect with the target connection, and return an error code if there are problems.
getErrorMessageHelper method that translates a connection error code into a string.
doSafetyChecksCheck that connecting the given connections is safe, meaning that it would not break any of Blockly's basic assumptions (e.g. no self connections).
doTypeChecksCheck whether this connection is compatible with another connection with respect to the value type system. E.g. square_root("Hello") is not compatible.
doDragChecksCheck whether this connection can be made by dragging.
canConnectToPrevious_Helper function for drag checking.

Constructors

Constructor

new ConnectionChecker(): ConnectionChecker;

Returns

ConnectionChecker

Methods

canConnect()

canConnect(
a,
b,
isDragging,
opt_distance?
): boolean;

Defined in: packages/blockly/core/connection_checker.ts:38

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

Parameters

ParameterTypeDescription
aConnection | nullConnection to check compatibility with.
bConnection | nullConnection to check compatibility with.
isDraggingbooleanTrue if the connection is being made by dragging a block.
opt_distance?numberThe max allowable distance between the connections for drag checks.

Returns

boolean

Whether the connection is legal.

Implementation of

IConnectionChecker.canConnect


canConnectWithReason()

canConnectWithReason(
a,
b,
isDragging,
opt_distance?
): number;

Defined in: packages/blockly/core/connection_checker.ts:62

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

Parameters

ParameterTypeDescription
aConnection | nullConnection to check compatibility with.
bConnection | nullConnection to check compatibility with.
isDraggingbooleanTrue if the connection is being made by dragging a block.
opt_distance?numberThe max allowable distance between the connections for drag checks.

Returns

number

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

Implementation of

IConnectionChecker.canConnectWithReason


getErrorMessage()

getErrorMessage(
errorCode,
a,
b
): string;

Defined in: packages/blockly/core/connection_checker.ts:102

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

Parameters

ParameterTypeDescription
errorCodenumberThe error code.
aConnection | nullOne of the two connections being checked.
bConnection | nullThe second of the two connections being checked.

Returns

string

A developer-readable error string.

Implementation of

IConnectionChecker.getErrorMessage


doSafetyChecks()

doSafetyChecks(a, b): number;

Defined in: packages/blockly/core/connection_checker.ts:148

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).

Parameters

ParameterTypeDescription
aConnection | nullThe first of the connections to check.
bConnection | nullThe second of the connections to check.

Returns

number

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

Implementation of

IConnectionChecker.doSafetyChecks


doTypeChecks()

doTypeChecks(a, b): boolean;

Defined in: packages/blockly/core/connection_checker.ts:203

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

Parameters

ParameterTypeDescription
aConnectionConnection to compare.
bConnectionConnection to compare against.

Returns

boolean

True if the connections share a type.

Implementation of

IConnectionChecker.doTypeChecks


doDragChecks()

doDragChecks(
a,
b,
distance
): boolean;

Defined in: packages/blockly/core/connection_checker.ts:229

Check whether this connection can be made by dragging.

Parameters

ParameterTypeDescription
aRenderedConnectionConnection to compare (on the block that's being dragged).
bRenderedConnectionConnection to compare against.
distancenumberThe maximum allowable distance between connections.

Returns

boolean

True if the connection is allowed during a drag.

Implementation of

IConnectionChecker.doDragChecks


canConnectToPrevious_()

protected canConnectToPrevious_(a, b): boolean;

Defined in: packages/blockly/core/connection_checker.ts:316

Helper function for drag checking.

Parameters

ParameterTypeDescription
aConnectionThe connection to check, which must be a statement input or next connection.
bConnectionA nearby connection to check, which must be a previous connection.

Returns

boolean

True if the connection is allowed, false otherwise.