MCPcopy
hub / github.com/RaspberryPiFoundation/blockly / connect_

Method connect_

packages/blockly/core/connection.ts:101–157  ·  view source on GitHub ↗

* Connect two connections together. This is the connection on the superior * block. * * @param childConnection Connection on inferior block.

(childConnection: Connection)

Source from the content-addressed store, hash-verified

99 * @param childConnection Connection on inferior block.
100 */
101 protected connect_(childConnection: Connection) {
102 const INPUT = ConnectionType.INPUT_VALUE;
103 const parentBlock = this.getSourceBlock();
104 const childBlock = childConnection.getSourceBlock();
105
106 // Make sure the childConnection is available.
107 if (childConnection.isConnected()) {
108 childConnection.disconnectInternal(false);
109 }
110
111 // Make sure the parentConnection is available.
112 let orphan;
113 if (this.isConnected()) {
114 const shadowState = this.stashShadowState();
115 const target = this.targetBlock();
116 if (target!.isShadow()) {
117 target!.dispose(false);
118 } else {
119 this.disconnectInternal();
120 orphan = target;
121 }
122 this.applyShadowState(shadowState);
123 }
124
125 // Connect the new connection to the parent.
126 let event;
127 if (eventUtils.isEnabled()) {
128 event = new (eventUtils.get(EventType.BLOCK_MOVE))(
129 childBlock,
130 ) as BlockMove;
131 event.setReason(['connect']);
132 }
133 connectReciprocally(this, childConnection);
134 childBlock.setParent(parentBlock);
135 if (event) {
136 event.recordNew();
137 eventUtils.fire(event);
138 }
139
140 // Deal with the orphan if it exists.
141 if (orphan) {
142 const orphanConnection =
143 this.type === INPUT
144 ? orphan.outputConnection
145 : orphan.previousConnection;
146 if (!orphanConnection) return;
147 const connection = Connection.getConnectionForOrphanedConnection(
148 childBlock,
149 orphanConnection,
150 );
151 if (connection) {
152 orphanConnection.connect(connection);
153 } else {
154 orphanConnection.onFailedConnect(this);
155 }
156 }
157 }
158

Callers 1

connectMethod · 0.95

Calls 15

getSourceBlockMethod · 0.95
isConnectedMethod · 0.95
disconnectInternalMethod · 0.95
stashShadowStateMethod · 0.95
targetBlockMethod · 0.95
applyShadowStateMethod · 0.95
isShadowMethod · 0.80
getMethod · 0.80
connectMethod · 0.80
connectReciprocallyFunction · 0.70
disposeMethod · 0.65

Tested by

no test coverage detected