You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This can return either a node or null if nothing is found at that path. And you can use element.assertNode(path) instead when you want to be sure of retrieving a node at the path. But this is awkward because it's easy to forget.
I think it might make sense to make this one throw if it doesn't find something. And potentially introduce an alternative Node.maybe(path) which can also return null. This way errors in path-based logic are more clear. And when you really want to check a path that might not exist it's more obvious.
I find that most of the time I'd like the assertion protection.
The text was updated successfully, but these errors were encountered:
I'm unsure about parts of this, but the one thing I am sure about is that I don't like the name maybe as a function of a Node. More broadly, my preference would be: element.getNode(path) will throw an error if there is no node at the path, but element.get(path) will just return whatever (if anything) is at the path (including null). These names make sense to me as getNode sounds more precise, whereas get is just 'give me whatever may be there'.
Do you want to request a feature or report a bug?
Idea / improvement.
What's the current behavior?
Right now we have:
This can return either a
node
ornull
if nothing is found at that path. And you can useelement.assertNode(path)
instead when you want to be sure of retrieving a node at the path. But this is awkward because it's easy to forget.What's the expected behavior?
In the future with #2495 we'll have:
I think it might make sense to make this one throw if it doesn't find something. And potentially introduce an alternative
Node.maybe(path)
which can also return null. This way errors in path-based logic are more clear. And when you really want to check a path that might not exist it's more obvious.I find that most of the time I'd like the assertion protection.
The text was updated successfully, but these errors were encountered: