-
Notifications
You must be signed in to change notification settings - Fork 333
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
Remove component init() methods and initialise in constructor #4011
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
domoscargin
force-pushed
the
bk-remove-init
branch
from
July 26, 2023 13:05
990e2f4
to
ef974c8
Compare
domoscargin
force-pushed
the
bk-remove-init
branch
from
July 26, 2023 13:15
ef974c8
to
e50be7b
Compare
packages/govuk-frontend/src/govuk/components/checkboxes/checkboxes.mjs
Outdated
Show resolved
Hide resolved
Because we're not storing the object we create using `new`, we're getting a `no-new` failure from eslint. We'll temporarily disable this warning, but plan to have a component registry in the future at which point we can store these objects there.
domoscargin
force-pushed
the
bk-remove-init
branch
from
July 26, 2023 14:17
e50be7b
to
ecd4f71
Compare
colinrotherham
approved these changes
Jul 26, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A work of wonder 🎉
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4008
What
Remove
init()
method from each component and move initialisation into constructor.Why
The init() method adds an unnecessary step for our components' initialisation,
without tangible benefits for what our components do. Without it we can simplify both how our components are initialised, as well as their internal implementation as we're looking to throw errors at instantiation.
Removing it entirely and moving its code to the constructor will ensure that components don't get a double initialisation by services that may have missed a .init() call during their migration. Instead, they'll get a clear error telling them that they're calling a method that no longer exists.
You can find more explanations of that decision in our decision record.
Notes
eslint
no-new
rule failseslint flags the fact that we don't store a reference to the constructed component when we instantiate it. We've decided to ignore this temporarily until we look at adding a component registry down the line.