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

Remove component init() methods and initialise in constructor #4011

Merged
merged 5 commits into from
Jul 26, 2023

Conversation

domoscargin
Copy link
Contributor

@domoscargin domoscargin commented Jul 26, 2023

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 fails

eslint 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.

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4011 July 26, 2023 13:03 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4011 July 26, 2023 13:05 Inactive
@domoscargin domoscargin marked this pull request as ready for review July 26, 2023 13:11
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4011 July 26, 2023 13:16 Inactive
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md 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.
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-4011 July 26, 2023 14:17 Inactive
Copy link
Contributor

@colinrotherham colinrotherham left a 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 🎉

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.

Remove init() method from our JavaScript components
3 participants