feat: Adds support for providing default URL parameters via the frontend #75
+74
−0
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.
This should resolve #49
This PR adds support for providing default URL values during runtime via the frontend. This works by providing methods within the
wayfinder.ts
that user-land code can call to set (or add individual) default parameters. These parameters are stored in a globalWayfinder
window object.When generating the URL for a controller, we merge in any set default parameters, making sure that we don't override any keys already set during the calling of the
url
method.Note: in theory we don't need to use a window object here, but when running the test suite, it seems like I was getting different instances of the
wayfinder.ts
file, the default parameters that were set were getting lost.Usage
Here's how I have it set up in our app. The benefit here is it is up to the user to decide where and when to apply the defaults:
One thing I have not figured out with this approach is non-optional parameters that do not have a default set via the URL facade on the backend. Wayfinder doesn't know that
domain
parameter is being set as a default and will be applied/set during theurl()
call: