add Podium context "invisible" getters for convenience and consistency #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Here is a proposal to make switching between podlet and layout accessing of the context a little more consistent. I realise that they can't entirely be the same due to the need for fetch values to be respected in some cases. (eg. public pathname) but this seemed like a possible way to avoid the confusion when accessing context values in a layout route.
What?
This PR adds an "invisible" getter property (get only, no write, non enumerable) for each parser using the registered key as the property. Since these are non enumerable, they will not show up in any serialisation.
Why?
It's confusing to users to have to access context values via a snake case string that also must include
podium-
at the beginning. Eg.res.locals.podium.context['podium-finn-token']
Example
Caveat
If a parser is a function, the getter will still return the function, it will not call the function so there is still room for some inconsistency between the layout and the podlet.