govuk-frontend
govuk-frontend copied to clipboard
Determine behaviour of `createAll` if `$scope` is `null`
What
We need to determine if the current behaviour of createAll
is correct as it stands (and update the documentation) or if we need to change it to take into account the case in which $scope
is null
.
Why
Currently if $scope
passed into createAll
is null
because typeof null === 'object'
it will throw a TypeError
.
The current behaviour of createAll
is that if $scope
is falsy (not defined) then we set the scope of createAll
to the document.
This raises the question; should the behaviour of createAll
when $scope
is falsy be the same as the behaviour of createAll
when $scope
is null
?
There is a potential scenario when a user might want createAll
to only execute on a specific $scope
if it is not null
and then not have it be executed on document
if $scope
is null
. It is not clear from the documentation what they should do in this specific scenario.
If our intended behaviour is that $scope
would default to document
if $scope
is null
and the user wouldn't want this to occur, we should probably add:
To prevent component being created if `$element` is undefined:
if ($element) {
createAll(ProjectComponent, undefined, $element)
}
to our documentation on creating components.
Otherwise if we want createAll
to not execute if $scope
is undefined then we'd need to change createAll
to detect when $scope
is null
.