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

Optional AllowedEvents/AllowedActions #446

Merged
merged 2 commits into from
Apr 19, 2021

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Apr 19, 2021

The restricted controller messenger now allows omitting allowedActions and allowedEvents. Technically it already allowed this, but it required setting the type of the allowed actions/events to an empty string. Now the type is never if no actions/events are used.

The restricted controller messenger now allows omitting allowedActions
and allowedEvents. Technically it already allowed this, but it required
setting the type of the allowed actions/events to an empty string. Now
the type is `never` if no actions/events are used.
@Gudahtt Gudahtt force-pushed the restricted-controller-messenger-optional-allowed branch from c81ceaf to 7c7eb66 Compare April 19, 2021 19:30
@@ -82,13 +82,13 @@ export class RestrictedControllerMessenger<
}: {
controllerMessenger: ControllerMessenger<Action, Event>;
name: N;
allowedActions: AllowedAction[];
allowedEvents: AllowedEvent[];
allowedActions?: AllowedAction[] | never;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per discussion, with ?:, is | never necessary or vice versa?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?: allows for null or undefined.

I believe this is stating that if it is defined it must be an AllowedEvent[] or it'll throw.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds reasonable to me 👍 I wasn't entirely sure of the exact behavior with never

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving the | never out also serves to ensure that this parameter must be an AllowedEvent[] though. I think it's superfluous.

I propagated it here because I used it in getRestrictedControllerMessenger, where I needed the type for AllowedEvents to be something because optional generic parameters aren't a thing that exists. So I need the | never for the generic parameters, but I'll remove them for the optional parameters (here and in getRestrictedControllerMessenger)

Copy link
Contributor

@ryanml ryanml left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@Gudahtt Gudahtt merged commit 644f980 into develop Apr 19, 2021
@Gudahtt Gudahtt deleted the restricted-controller-messenger-optional-allowed branch April 19, 2021 21:37
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
The restricted controller messenger now allows omitting allowedActions
and allowedEvents. Technically it already allowed this, but it required
setting the type of the allowed actions/events to an empty string. Now
the type is `never` if no actions/events are used.
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
The restricted controller messenger now allows omitting allowedActions
and allowedEvents. Technically it already allowed this, but it required
setting the type of the allowed actions/events to an empty string. Now
the type is `never` if no actions/events are used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants