Skip to main content

Class: ConnectionDB

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

Database of connections. Connections are stored in order of their vertical component. This way connections in an area may be looked up quickly using a binary search.

Methods index​

MethodDescription
removeConnectionRemove a connection from the database. Must already exist in DB.
reorderConnectionMoves the given connection in the connection DB to reflect its new Y position. For performance, this will be deferred if the connection DB is in the middle of a bulk update.
getNeighboursFind all nearby connections to the given connection. Type checking does not apply, since this function is used for bumping.
searchForClosestFind the closest compatible connection to this connection.
initInitialize a set of connection DBs for a workspace.

Constructors​

Constructor​

new ConnectionDB(connectionChecker): ConnectionDB;

Defined in: packages/blockly/core/connection_db.ts:40

Parameters​

ParameterTypeDescription
connectionCheckerIConnectionCheckerThe workspace's connection type checker, used to decide if connections are valid during a drag.

Returns​

ConnectionDB

Methods​

removeConnection()​

removeConnection(connection, yPos): void;

Defined in: packages/blockly/core/connection_db.ts:135

Remove a connection from the database. Must already exist in DB.

Parameters​

ParameterTypeDescription
connectionRenderedConnectionThe connection to be removed.
yPosnumberThe y position used to find the index of the connection.

Returns​

void

Throws​

If the connection cannot be found in the database.


reorderConnection()​

reorderConnection(connection, newYPos): void;

Defined in: packages/blockly/core/connection_db.ts:153

Moves the given connection in the connection DB to reflect its new Y position. For performance, this will be deferred if the connection DB is in the middle of a bulk update.

Parameters​

ParameterTypeDescription
connectionRenderedConnectionThe connection that is moving. Should be provided before its Connection.y field has been updated.
newYPosnumberThe y coordinate (in workspace units) to which the connection will move.

Returns​

void


getNeighbours()​

getNeighbours(connection, maxRadius): RenderedConnection[];

Defined in: packages/blockly/core/connection_db.ts:168

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

Parameters​

ParameterTypeDescription
connectionRenderedConnectionThe connection whose neighbours should be returned.
maxRadiusnumberThe maximum radius to another connection.

Returns​

RenderedConnection[]

List of connections.


searchForClosest()​

searchForClosest(
conn,
maxRadius,
dxy
): object;

Defined in: packages/blockly/core/connection_db.ts:247

Find the closest compatible connection to this connection.

Parameters​

ParameterTypeDescription
connRenderedConnectionThe connection searching for a compatible mate.
maxRadiusnumberThe maximum radius to another connection.
dxyCoordinateOffset between this connection's location in the database and the current location (as a result of dragging).

Returns​

object

Contains two properties: 'connection' which is either another connection or null, and 'radius' which is the distance.

connection​
connection: RenderedConnection | null;
radius​
radius: number;

init()​

static init(checker): ConnectionDB[];

Defined in: packages/blockly/core/connection_db.ts:352

Initialize a set of connection DBs for a workspace.

Parameters​

ParameterTypeDescription
checkerIConnectionCheckerThe workspace's connection checker, used to decide if connections are valid during a drag.

Returns​

ConnectionDB[]

Array of databases.