Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore ComposableController compatibility between different BaseControllers #458

Merged
merged 2 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/BaseControllerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ export class BaseController<

public readonly metadata: StateMetadata<S>;

/**
* The existence of the `subscribe` property is how the ComposableController detects whether a
* controller extends the old BaseController or the new one. We set it to `never` here to ensure
* this property is never used for new BaseController-based controllers, to ensure the
* ComposableController never mistakes them for an older style controller.
*/
public readonly subscribe: never;

/**
* Creates a BaseController instance.
*
Expand Down
4 changes: 2 additions & 2 deletions src/ComposableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class ComposableController extends BaseController<never, any> {
this.messagingSystem = messenger;
this.controllers.forEach((controller) => {
const { name } = controller;
if (controller instanceof BaseController) {
controller.subscribe((state) => {
if ((controller as BaseController<any, any>).subscribe !== undefined) {
(controller as BaseController<any, any>).subscribe((state) => {
this.update({ [name]: state });
});
} else if (this.messagingSystem) {
Expand Down