@@ -55,10 +55,10 @@ interface MechanismComponentHolderMixin extends MechanismComponentHolderMixinTyp
55
55
mrcHideMechanisms : boolean ;
56
56
mrcHidePrivateComponents : boolean ;
57
57
58
- mrcMechanismIds : string [ ] ,
59
- mrcComponentIds : string [ ] ,
60
- mrcPrivateComponentIds : string [ ] ,
61
- mrcEventIds : string [ ] ,
58
+ mrcMechanismBlockIds : string ,
59
+ mrcComponentBlockIds : string ,
60
+ mrcPrivateComponentBlockIds : string ,
61
+ mrcEventBlockIds : string ,
62
62
mrcToolboxUpdateTimeout : NodeJS . Timeout | null ;
63
63
}
64
64
type MechanismComponentHolderMixinType = typeof MECHANISM_COMPONENT_HOLDER ;
@@ -71,10 +71,10 @@ const MECHANISM_COMPONENT_HOLDER = {
71
71
this . setInputsInline ( false ) ;
72
72
this . setOutput ( false ) ;
73
73
this . setStyle ( MRC_STYLE_MECHANISMS ) ;
74
- this . mrcMechanismIds = [ ] ;
75
- this . mrcComponentIds = [ ] ;
76
- this . mrcPrivateComponentIds = [ ] ;
77
- this . mrcEventIds = [ ] ;
74
+ this . mrcMechanismBlockIds = '' ;
75
+ this . mrcComponentBlockIds = '' ;
76
+ this . mrcPrivateComponentBlockIds = '' ;
77
+ this . mrcEventBlockIds = '' ;
78
78
this . mrcToolboxUpdateTimeout = null ;
79
79
} ,
80
80
saveExtraState : function ( this : MechanismComponentHolderBlock ) : MechanismComponentHolderExtraState {
@@ -134,23 +134,30 @@ const MECHANISM_COMPONENT_HOLDER = {
134
134
mrcOnLoad : function ( this : MechanismComponentHolderBlock ) : void {
135
135
this . collectDescendants ( false ) ;
136
136
} ,
137
+ /**
138
+ * mrcOnDescendantDisconnect is called for each MechanismComponentHolderBlock when any descendant is
139
+ * disconnected.
140
+ */
141
+ mrcOnDescendantDisconnect : function ( this : MechanismComponentHolderBlock ) : void {
142
+ this . collectDescendants ( true ) ;
143
+ } ,
137
144
mrcDescendantsMayHaveChanged : function ( this : MechanismComponentHolderBlock ) : void {
138
145
this . collectDescendants ( true ) ;
139
146
} ,
140
147
collectDescendants : function (
141
148
this : MechanismComponentHolderBlock , updateToolboxIfDescendantsChanged : boolean ) : void {
142
- const mechanismIds : string [ ] = [ ] ;
143
- const componentIds : string [ ] = [ ] ;
144
- const privateComponentIds : string [ ] = [ ] ;
145
- const eventIds : string [ ] = [ ] ;
149
+ let mechanismBlockIds = '' ;
150
+ let componentBlockIds = '' ;
151
+ let privateComponentBlockIds = '' ;
152
+ let eventBlockIds = '' ;
146
153
147
154
const mechanismsInput = this . getInput ( INPUT_MECHANISMS ) ;
148
155
if ( mechanismsInput && mechanismsInput . connection ) {
149
156
// Walk through all connected mechanism blocks.
150
157
let mechanismBlock = mechanismsInput . connection . targetBlock ( ) ;
151
158
while ( mechanismBlock ) {
152
159
if ( mechanismBlock . type === MRC_MECHANISM_NAME ) {
153
- mechanismIds . push ( ( mechanismBlock as MechanismBlock ) . getMechanismId ( ) ) ;
160
+ mechanismBlockIds += mechanismBlock . id ;
154
161
}
155
162
// Move to the next block in the stack.
156
163
mechanismBlock = mechanismBlock . getNextBlock ( ) ;
@@ -162,7 +169,7 @@ const MECHANISM_COMPONENT_HOLDER = {
162
169
let componentBlock = componentsInput . connection . targetBlock ( ) ;
163
170
while ( componentBlock ) {
164
171
if ( componentBlock . type === MRC_COMPONENT_NAME ) {
165
- componentIds . push ( ( componentBlock as ComponentBlock ) . getComponentId ( ) ) ;
172
+ componentBlockIds += componentBlock . id ;
166
173
}
167
174
// Move to the next block in the stack.
168
175
componentBlock = componentBlock . getNextBlock ( ) ;
@@ -174,7 +181,7 @@ const MECHANISM_COMPONENT_HOLDER = {
174
181
let componentBlock = privateComponentsInput . connection . targetBlock ( ) ;
175
182
while ( componentBlock ) {
176
183
if ( componentBlock . type === MRC_COMPONENT_NAME ) {
177
- privateComponentIds . push ( ( componentBlock as ComponentBlock ) . getComponentId ( ) ) ;
184
+ privateComponentBlockIds += componentBlock . id ;
178
185
}
179
186
// Move to the next block in the stack.
180
187
componentBlock = componentBlock . getNextBlock ( ) ;
@@ -186,65 +193,26 @@ const MECHANISM_COMPONENT_HOLDER = {
186
193
let eventBlock = eventsInput . connection . targetBlock ( ) ;
187
194
while ( eventBlock ) {
188
195
if ( eventBlock . type === MRC_EVENT_NAME ) {
189
- eventIds . push ( ( eventBlock as EventBlock ) . getEventId ( ) ) ;
196
+ eventBlockIds += eventBlock . id ;
190
197
}
191
198
// Move to the next block in the stack.
192
199
eventBlock = eventBlock . getNextBlock ( ) ;
193
200
}
194
201
}
195
202
196
203
if ( updateToolboxIfDescendantsChanged ) {
197
- let descendantsChanged = false ;
198
- if ( mechanismIds . length === this . mrcMechanismIds . length ) {
199
- for ( let i = 0 ; i < mechanismIds . length ; i ++ ) {
200
- if ( mechanismIds [ i ] !== this . mrcMechanismIds [ i ] ) {
201
- descendantsChanged = true ;
202
- break ;
203
- }
204
- }
205
- } else {
206
- descendantsChanged = true ;
207
- }
208
- if ( componentIds . length === this . mrcComponentIds . length ) {
209
- for ( let i = 0 ; i < componentIds . length ; i ++ ) {
210
- if ( componentIds [ i ] !== this . mrcComponentIds [ i ] ) {
211
- descendantsChanged = true ;
212
- break ;
213
- }
214
- }
215
- } else {
216
- descendantsChanged = true ;
217
- }
218
- if ( privateComponentIds . length === this . mrcPrivateComponentIds . length ) {
219
- for ( let i = 0 ; i < privateComponentIds . length ; i ++ ) {
220
- if ( privateComponentIds [ i ] !== this . mrcPrivateComponentIds [ i ] ) {
221
- descendantsChanged = true ;
222
- break ;
223
- }
224
- }
225
- } else {
226
- descendantsChanged = true ;
227
- }
228
- if ( eventIds . length === this . mrcEventIds . length ) {
229
- for ( let i = 0 ; i < eventIds . length ; i ++ ) {
230
- if ( eventIds [ i ] !== this . mrcEventIds [ i ] ) {
231
- descendantsChanged = true ;
232
- break ;
233
- }
234
- }
235
- } else {
236
- descendantsChanged = true ;
237
- }
238
-
239
- if ( descendantsChanged ) {
204
+ if ( mechanismBlockIds !== this . mrcMechanismBlockIds ||
205
+ componentBlockIds !== this . mrcComponentBlockIds ||
206
+ privateComponentBlockIds !== this . mrcPrivateComponentBlockIds ||
207
+ eventBlockIds !== this . mrcEventBlockIds ) {
240
208
this . updateToolboxAfterDelay ( ) ;
241
209
}
242
210
}
243
211
244
- this . mrcMechanismIds = mechanismIds ;
245
- this . mrcComponentIds = componentIds ;
246
- this . mrcPrivateComponentIds = privateComponentIds ;
247
- this . mrcEventIds = eventIds ;
212
+ this . mrcMechanismBlockIds = mechanismBlockIds ;
213
+ this . mrcComponentBlockIds = componentBlockIds ;
214
+ this . mrcPrivateComponentBlockIds = privateComponentBlockIds ;
215
+ this . mrcEventBlockIds = eventBlockIds ;
248
216
} ,
249
217
updateToolboxAfterDelay : function ( this : MechanismComponentHolderBlock ) : void {
250
218
if ( this . mrcToolboxUpdateTimeout ) {
0 commit comments