Skip to content

Commit bdc167c

Browse files
committed
If a controller is V1 but it has a messaging system, subscribe to its stateChange event
1 parent 599fd44 commit bdc167c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/composable-controller/src/ComposableController.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ export class ComposableController extends BaseController<
166166
* @param controller - Controller instance to update
167167
*/
168168
#updateChildController(controller: ControllerInstance): void {
169+
if (!isBaseController(controller) && !isBaseControllerV1(controller)) {
170+
throw new Error(
171+
'Invalid controller: controller must extend from BaseController or BaseControllerV1',
172+
);
173+
}
174+
169175
const { name } = controller;
170176
if (isBaseControllerV1(controller)) {
171177
controller.subscribe((childState) => {
@@ -174,7 +180,11 @@ export class ComposableController extends BaseController<
174180
[name]: childState,
175181
}));
176182
});
177-
} else if (isBaseController(controller)) {
183+
}
184+
if (
185+
(isBaseControllerV1(controller) && 'messagingSystem' in controller) ||
186+
isBaseController(controller)
187+
) {
178188
this.messagingSystem.subscribe(
179189
`${name}:stateChange`,
180190
(childState: StateConstraint) => {
@@ -184,10 +194,6 @@ export class ComposableController extends BaseController<
184194
}));
185195
},
186196
);
187-
} else {
188-
throw new Error(
189-
'Invalid controller: controller must extend from BaseController or BaseControllerV1',
190-
);
191197
}
192198
}
193199
}

0 commit comments

Comments
 (0)