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

[Stretch] Investigate how to prevent component initialisation based on a condition #5225

Closed
3 tasks
Tracked by #5205 ...
romaricpascal opened this issue Aug 9, 2024 · 2 comments · Fixed by #5336
Closed
3 tasks
Tracked by #5205 ...
Assignees

Comments

@romaricpascal
Copy link
Member

romaricpascal commented Aug 9, 2024

What

Investigate how to prevent component initialisation based on a condition, like Analytics needing users to have accepted cookies on the Design System site.

Why

This would offer a consistent way to initialise components that require a little check before actually being initialised, without having to actually instantiate them.

Who needs to work on this

Developers

Who needs to review this

Developers

Done when

  • We've designed the feature
  • We've implemented the feature
  • We've documented the feature
@romaricpascal romaricpascal moved this to Backlog 🏃🏼‍♀️ in GOV.UK Design System cycle board Aug 9, 2024
@romaricpascal romaricpascal changed the title [Stretch] Allow createAll to skip initialising components based on conditions (eg. Analytics and having accepted cookies) [Stretch] Investigate how to prevent component initialisation based on a condition Aug 9, 2024
@romaricpascal
Copy link
Member Author

This would provide a clear point for checking the presence of specific APIs, like in the Copy component of the Design System.

@romaricpascal
Copy link
Member Author

Having a separate method to check if specific APIs are supported overlaps a lot with isSupported, made @protected in #5323. We've decided to merge the two approaches and make checkSupport static and protected, which will allow it to:

  • be called by createAll ahead of looping on all components, saving unnecessary looping
  • be overridden by child classes if a component or components have other conditions to check, like the availability of an API.

Child classes overriding the method will be able to throw whatever Error they see fit when support is not available for the component, which:

  • reduces the logistics the base class needs to be responsible for
  • allows child classes to send a custom message
  • will fit into createAll's way of catching these errors during initialisation
  • makes use of JavaScript's native capabilities for throwing errors rather than returning a boolean, then having the base class throw an error.

@romaricpascal romaricpascal linked a pull request Sep 23, 2024 that will close this issue
@patrickpatrickpatrick patrickpatrickpatrick moved this from Needs review 🔍 to Ready to release 🚀 in GOV.UK Design System cycle board Sep 24, 2024
@domoscargin domoscargin moved this from Ready to release 🚀 to Done 🏁 in GOV.UK Design System cycle board Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants