Class: Connection

Constructor

Connection

new Connection(source, type)

Class for a connection between blocks.

Parameter

source

Blockly.Block

The block establishing this connection.

Value must not be null.

type

number

The type of the connection.

Implements
Blockly.IASTNodeLocationWithBlock

Properties

CAN_CONNECT

static

Constants for checking whether two connections are compatible.

disposed

package

boolean

Has this connection been disposed of?

sourceBlock_

protected

non-null Blockly.Block

targetConnection

Blockly.Connection

Connection this connection connects to. Null if not connected.

type

number

x

package

number

Horizontal location of this connection.

y

package

number

Vertical location of this connection.

Methods

lastConnectionInRow

package   static

lastConnectionInRow(startBlock, orphanBlock) returns Blockly.Connection

Walks down a row a blocks, at each stage checking if there are any connections that will accept the orphaned block. If at any point there are zero or multiple eligible connections, returns null. Otherwise returns the only input on the last block in the chain. Terminates early for shadow blocks.

Parameter

startBlock

Blockly.Block

The block on which to start the search.

Value must not be null.

orphanBlock

Blockly.Block

The block that is looking for a home.

Value must not be null.

Returns

Blockly.Connection The suitable connection point on the chain of blocks, or null.

canConnectWithReason

canConnectWithReason(target) returns number

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

Parameter

target

Blockly.Connection

Connection to check compatibility with.

Returns

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

checkConnection

package

checkConnection(target)

Checks whether the current connection and target connection are compatible and throws an exception if they are not.

Parameter

target

Blockly.Connection

The connection to check compatibility with.

checkType

checkType(otherConnection) returns boolean

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

Parameter

otherConnection

Blockly.Connection

Connection to compare against.

Value must not be null.

Returns

boolean True if the connections share a type.

connect

connect(otherConnection)

Connect this connection to another connection.

Parameter

otherConnection

Blockly.Connection

Connection to connect to.

Value must not be null.

connect_

protected

connect_(childConnection)

Connect two connections together. This is the connection on the superior block.

Parameter

childConnection

Blockly.Connection

Connection on inferior block.

Value must not be null.

disconnect

disconnect()

Disconnect this connection.

disconnectInternal_

protected

disconnectInternal_(parentBlock, childBlock)

Disconnect two blocks that are connected by this connection.

Parameter

parentBlock

Blockly.Block

The superior block.

Value must not be null.

childBlock

Blockly.Block

The inferior block.

Value must not be null.

dispose

package

dispose()

Dispose of this connection and deal with connected blocks.

getCheck

public

getCheck() returns Array

Get a connection's compatibility.

Returns

Array List of compatible value types. Null if all types are compatible.

getParentInput

package

getParentInput() returns Blockly.Input

Get the parent input of a connection.

Returns

Blockly.Input The input that the connection belongs to or null if no parent exists.

getShadowDom

getShadowDom() returns Element

Return a connection's shadow block.

Returns

Element Shadow DOM representation of a block or null.

getSourceBlock

getSourceBlock() returns Blockly.Block

Get the source block for this connection.

Implements
Blockly.IASTNodeLocationWithBlock#getSourceBlock
Returns

non-null Blockly.Block The source block.

isConnected

isConnected() returns boolean

Is the connection connected?

Returns

boolean True if connection is connected to another connection.

isConnectionAllowed

isConnectionAllowed(candidate) returns boolean

Check if the two connections can be dragged to connect to each other.

Parameter

candidate

Blockly.Connection

A nearby connection to check.

Value must not be null.

Returns

boolean True if the connection is allowed, false otherwise.

isSuperior

isSuperior() returns boolean

Does the connection belong to a superior block (higher in the source stack)?

Returns

boolean True if connection faces down or right.

neighbours

package

neighbours(_maxLimit) returns Array of non-null Blockly.Connection

Find all nearby compatible connections to this connection. Type checking does not apply, since this function is used for bumping.

Headless configurations (the default) do not have neighboring connection, and always return an empty list (the default). Blockly.RenderedConnection overrides this behavior with a list computed from the rendered positioning.

Parameter

_maxLimit

number

The maximum radius to another connection.

Returns

non-null Array of non-null Blockly.Connection List of connections.

onCheckChanged_

protected

onCheckChanged_()

Function to be called when this connection's compatible types have changed.

onFailedConnect

package

onFailedConnect(_otherConnection)

Behavior after a connection attempt fails.

Parameter

_otherConnection

Blockly.Connection

Connection that this connection failed to connect to.

Value must not be null.

respawnShadow_

protected

respawnShadow_()

Respawn the shadow block if there was one connected to the this connection.

setCheck

setCheck(check) returns Blockly.Connection

Change a connection's compatibility.

Parameter

check

(string or non-null Array of string)

Compatible value type or list of value types. Null if all types are compatible.

Value may be null.

Returns

non-null Blockly.Connection The connection being modified (to allow chaining).

setShadowDom

setShadowDom(shadow)

Change a connection's shadow block.

Parameter

shadow

Element

DOM representation of a block or null.

targetBlock

targetBlock() returns Blockly.Block

Returns the block that this connection connects to.

Returns

Blockly.Block The connected block or null if none is connected.

toString

toString() returns string

This method returns a string describing this Connection in developer terms (English only). Intended to on be used in console logs and errors.

Returns

string The description.