Blockly. Connection
Class for a connection between blocks.
Constructor
Connection
new Connection(source, type)
Parameter |
|
---|---|
source |
The block establishing this connection. Value must not be null. |
type |
The type of the connection. |
- Implements
- Blockly.IASTNodeLocationWithBlock
Properties
CAN_CONNECT
Constants for checking whether two connections are compatible.
disposed
boolean
Has this connection been disposed of?
sourceBlock_
non-null Blockly.Block
targetConnection
Connection this connection connects to. Null if not connected.
type
number
x
number
Horizontal location of this connection.
y
number
Vertical location of this connection.
Methods
getConnectionForOrphanedConnection
getConnectionForOrphanedConnection(startBlock, orphanConnection) returns Blockly.Connection
Returns the connection (starting at the startBlock) which will accept the given connection. This includes compatible connection types and connection checks.
Parameter |
|
---|---|
startBlock |
The block on which to start the search. Value must not be null. |
orphanConnection |
The connection that is looking for a home. Value must not be null. |
- Returns
-
nullable Blockly.Connection
The suitable connection point on the chain of blocks, or null.
connect
connect(otherConnection) returns boolean
Connect this connection to another connection.
Parameter |
|
---|---|
otherConnection |
Connection to connect to. Value must not be null. |
- Returns
-
boolean
Whether the the blocks are now connected or not.
connect_
connect_(childConnection)
Connect two connections together. This is the connection on the superior block.
Parameter |
|
---|---|
childConnection |
Connection on inferior block. Value must not be null. |
disconnect
disconnect()
Disconnect this connection.
disconnectInternal_
disconnectInternal_(parentBlock, childBlock)
Disconnect two blocks that are connected by this connection.
Parameter |
|
---|---|
parentBlock |
The superior block. Value must not be null. |
childBlock |
The inferior block. Value must not be null. |
dispose
dispose()
Dispose of this connection and deal with connected blocks.
getCheck
getCheck() returns Array
Get a connection's compatibility.
- Returns
-
nullable Array
List of compatible value types. Null if all types are compatible.
getConnectionChecker
getConnectionChecker() returns Blockly.IConnectionChecker
Get the workspace's connection type checker object.
- Returns
-
non-null Blockly.IConnectionChecker
The connection type checker for the source block's workspace.
getParentInput
getParentInput() returns Blockly.Input
Get the parent input of a connection.
- Returns
-
nullable Blockly.Input
The input that the connection belongs to or null if no parent exists.
getShadowDom
getShadowDom(returnCurrent) returns Element
Returns the xml representation of the connection's shadow block.
Parameter |
|
---|---|
returnCurrent |
Optional boolean If true, and the shadow block is currently attached to this connection, this serializes the state of that block and returns it (so that field values are correct). Otherwise the saved shadowDom is just returned. |
- Returns
-
nullable Element
Shadow DOM representation of a block or null.
getShadowState
getShadowState(returnCurrent) returns Blockly.serialization.blocks.State
Returns the serialized object representation of the connection's shadow block.
Parameter |
|
---|---|
returnCurrent |
Optional boolean If true, and the shadow block is currently attached to this connection, this serializes the state of that block and returns it (so that field values are correct). Otherwise the saved state is just returned. |
- Returns
-
nullable Blockly.serialization.blocks.State
Serialized object representation of the 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.
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
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_
onCheckChanged_()
Function to be called when this connection's compatible types have changed.
onFailedConnect
onFailedConnect(_otherConnection)
Called when an attempted connection fails. NOP by default (i.e. for headless workspaces).
Parameter |
|
---|---|
_otherConnection |
Connection that this connection failed to connect to. Value must not be null. |
respawnShadow_
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(shadowDom)
Changes the connection's shadow block.
Parameter |
|
---|---|
shadowDom |
Element DOM representation of a block or null. Value may be null. |
setShadowState
setShadowState(shadowState)
Changes the connection's shadow block.
Parameter |
|
---|---|
shadowState |
Blockly.serialization.blocks.State An state represetation of the block or null. Value may be null. |
targetBlock
targetBlock() returns Blockly.Block
Returns the block that this connection connects to.
- Returns
-
nullable 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.