-
Notifications
You must be signed in to change notification settings - Fork 348
Fix handling of scope being null when calling createAll() or initAll()
#6164
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
Conversation
createAll() and initAll()
|
Hey @colinrotherham 👋🏻 Thanks for taking the time to raise this 🙏🏻 There's quite a lot of changes in this pull request – would you be up for splitting out some of the commits into separate pull requests to make it easier for us to review? From a quick glance we think:
We're also not sure about f8384bc – although Finally, having discussed what the behaviour should be if you pass a We think that it'd make more sense to treat it as an error, and either call |
|
@36degrees Happy to split them out where possible, not a problem at all I might hit issues trying to do stacked PRs from a fork, unless you know a way? Standalone console.log spies
Yeah this commit can stand alone, but do you mind if I include it? This was because only some of your tests add the spy whereas other test assertions rely on it existing from previous tests. When it came to adding Error handling
Ahh I'd assumed we'd copy But that sounds good, happy to treat it as an error instead Static methods and propertiesRegarding this bit:
It was in the sense that static methods and properties are available: childConstructor.checkSupport()
childConstructor.moduleNameSo it seemed odd to use two camelCase names Classes versus instancesPart of the type fixes were to distinguish between:
Once that was done it fixes the issue in this big comment but now the compiler realises we're passing configs into non-configurable components so aeaaff5 and 9e20b98 might need to all stay together I'll see what I can do |
IMO the snake-casing is appropriate here as it's an indicator that there's an extra level of indirection involved – When you're calling When you're accessing the Does that makes sense? |
Yeah 100% understand why for both, those two different names caught me out Unfortunately I've struggled to split this work out 😔 Your ESLint setup skips
Without
How do you feel about fixing this so ESLint can spot where There are some brilliant updates that are skipped currently and the blog post The Problem With Projects will fix both the null/undefined checks and some slow linting issues you've probably run into: - "@typescript-eslint/eslint-plugin": "^7.17.0",
- "@typescript-eslint/parser": "^7.17.0",
+ "@typescript-eslint/eslint-plugin": "^8.39.0",
+ "@typescript-eslint/parser": "^8.38.0",Separate PR of course But any ideas on how to do a stacked PR from a fork? |
Ahh I remember now, because it went to PascalCase again in the function createAll(Component, config, createAllOptions) {}
function formatErrorMessage(Component, message) {}
function normaliseDataset(Component, dataset) {} |
6401c1d to
bcdc9d6
Compare
|
@36degrees Can you check these commits before I open another PR? I've made the changes to throw |
|
Thanks for doing this @colinrotherham! The changes to throw the Can we drop the changes in 529df88? We appreciate you picking that up, but we think we need to handle that refactor ourselves to be sure we completely understand what's going on with our types, and share that knowledge around the team. The other thing that we're not sure about is the changes in bcdc9d6 – what's the benefit of overloading the function signature in this way, rather than the previous approach? It seems to introduce a lot of repetition and verbosity. |
|
@36degrees Ah I didn't expect you to look at those anymore, I've prepared these commits only and can drop the rest Yep overloads are definitely super repetitive but they can generate clear documentation on the three distinct ways E.g. If you pass in an HTML element to the third parameter, your editor will show They're great when one of the combinations needs to be deprecated, as ESLint can tell you which overload to use instead For example, the 3rd parameter can be an error handler function (not an object) but it isn't documented so maybe that combination should be deprecated?
Update: Dropped |
bcdc9d6 to
40feb52
Compare
|
How's it looking @36degrees? |
40feb52 to
eb9a428
Compare
This means we can throw multiple errors yet catch them in a single place
Unfortunately `typeof null === 'object'` passes
eb9a428 to
0715805
Compare
|
I've rebased this now since #6180 was merged |
36degrees
left a comment
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.
Thanks for this @colinrotherham – just noticed a couple of small things that it'd be good to get resolved if you've got time.
| function initAll(config) { | ||
| config = typeof config !== 'undefined' ? config : {} | ||
| function initAll(config = {}) { | ||
| const options = normaliseOptions(config) |
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.
This has the side-effect that initAll can now be called with an HTMLElement that will be used as the scope, or a function that will be used as the onError callback.
Do we need to update the type definition for config to reflect that?
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.
Of course! Yeah we support initAll($scope) in NHS.UK frontend for legacy reasons
If you're happy to have it here too?
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.
Yeah. It wasn't something we were looking at doing, but I think it makes sense from a consistency point of view and makes it slightly easier to maintain.
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.
Pushed 👍
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.
With those commits we removed on another branch if you need them
romaricpascal
left a comment
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.
Cheers for fixing this and moving the overload code to a separate branch!
createAll() and initAll()null when calling createAll() and initAll()
null when calling createAll() and initAll()null when calling createAll() or initAll()
Add changelog entry for #6164

Hello from the NHS digital service manual team 👋
We've been doing lots of testing of
createAll()andinitAll()on optional or dynamically created HTMLThis PR fixes a couple of issues affecting scoped initialisation I raised earlier today:
createAll()with scope not found #6161initAll()when scope not found #6162We also noticed that
createAll()passes configs to non-configurable components so we've fixed this, updated some tests, and I've had a go at the stretch task from @romaricpascal so the compiler can spot this in future in:Happy to tweak things, adjust naming conventions, or talk you through anything 😊