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

Plugin input #4704

Merged
merged 2 commits into from Mar 19, 2023
Merged

Plugin input #4704

merged 2 commits into from Mar 19, 2023

Conversation

brunnre8
Copy link
Member

@brunnre8 brunnre8 commented Mar 4, 2023

This types the public command API during the registration phase and reworks the input function to be a bit easier to understand, least for me.

Holler if you disagree, but I hate the pattern of

if(stuff) {
 // ...
} else if (other) {
 // ...
} else if (yet another) {
 // ...
}
// return

That (implicit) return right there is not even on screen when you start to read the first few clauses, so you have no idea what the function does at the end only to then scroll down and find out that it indeed just returns.

We already know that we are done, tell the reader accordingly.

@brunnre8 brunnre8 added Meta: Internal This is an internal codebase change (testing, linting, etc.). Status: needs-review PR not yet reviewed by enough maintainers labels Mar 12, 2023
server/client.ts Outdated

if (inputs.userInputs.has(cmd)) {
const plugin = inputs.userInputs.get(cmd);
const plugin = inputs.userInputs.get(cmd)!; // this is only save because we just checked it
Copy link
Member

Choose a reason for hiding this comment

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

nit: I meant to suggest changes here, but I'd prefer something like #4714

Copy link
Member Author

@brunnre8 brunnre8 Mar 16, 2023

Choose a reason for hiding this comment

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

your PR over there fails the typing check though

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Keep happy path on the left and try to return as early
as we can to help the reader understand the logic better

The function is too large to be able to quickly scan an if / else
chain and see the function return at the end
@brunnre8 brunnre8 removed the Status: needs-review PR not yet reviewed by enough maintainers label Mar 17, 2023
@brunnre8 brunnre8 merged commit e8b6434 into master Mar 19, 2023
@brunnre8 brunnre8 deleted the pluginInput branch March 19, 2023 12:02
@MaxLeiter MaxLeiter added this to the 4.4.0 milestone Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meta: Internal This is an internal codebase change (testing, linting, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants