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

[composable-controller] Enable handling of input that includes non-controllers with empty state #4444

Open
MajorLift opened this issue Jun 21, 2024 · 0 comments
Assignees

Comments

@MajorLift
Copy link
Contributor

MajorLift commented Jun 21, 2024

Explanation

Some of our classes that were previously labeled as controllers have empty state, making them non-controllers.

As part of Wallet Framework team's Q2 2024 OKRs (O3KR1), we're currently in the process of upgrading these non-controllers to use the messenger pattern without inheriting from BaseController.

As downstream usage of the ComposableController includes passing in these non-controllers as child controllers, we should define a consistent behavior for handling non-controller input.

  • a) We could simply reject non-controllers both at the type-level and at runtime, or
  • b) we could accept non-controllers as child controllers but handle them so that the ComposableController instance doesn't subscribe to their non-existent stateChange events (i.e. The following message should not be logged to console for non-controllers: "Error: Event missing from allow list: ExampleController:stateChange"), and
    • b-1) exclude the non-controllers from the composed state object entirely, or
    • b-2) include the non-controllers as properties in the composed state object, with empty objects assigned to the names of the non-controllers.

Proof of concept

The following logic could be moved into the ComposableController constructor:

    new ComposableController<
      Exclude<EngineState, keyof NonControllers>,
      Controllers[Exclude<keyof Controllers, keyof NonControllers>]
    >({
      controllers: controllers.filter(
        (
          controller,
        ): controller is Controllers[Exclude<
          keyof Controllers,
          keyof NonControllers
        >] =>
          'state' in controller &&
          controller.state !== undefined &&
          Object.keys(controller.state).length > 0,
      ),
      messenger: ...
    });

References

@MajorLift MajorLift changed the title [composable-controller] Non-controllers with empty state should be rejected or handled as redundant parameters [composable-controller] Non-controllers with empty state should be rejected or excluded from composed state Jun 21, 2024
@MajorLift MajorLift self-assigned this Jun 27, 2024
@MajorLift MajorLift removed their assignment Aug 2, 2024
@MajorLift MajorLift changed the title [composable-controller] Non-controllers with empty state should be rejected or excluded from composed state [composable-controller] Enable handling of input that includes non-controllers with empty state Nov 14, 2024
@MajorLift MajorLift self-assigned this Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant