Skip to content
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

Add ability to pass in custom getLocation 🥳 #239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

agirton
Copy link

@agirton agirton commented Feb 6, 2019

Problem

Issue #152 shows that a few application authors were wanting to automatically parse the search property. This way they don't need to implement the parse logic on their end. Some suggested to wrap the history with the own implementation so it would also handle outgoing navigation.

Reach Router with good reason does not handle this because there are so many query parsing libraries out there and not bundling this in it keeps this package small.

Possible Solution

To help application authors who want to parse the search property into their own query object, Reach Router could allow them to pass in a custom getLocation into the options.

Downsides

This will require users to duplicate the mapping of the source object like you have in the history file. I considered still using the "private" getLocation as the default, but was concerned that some users wouldn't want any default logic and they would apply that themselves.

Changes

Made options argument a object with a default value

I noticed options is not currently used so I made it an object and used default values for the getLocation. The benefit of this approach is it pushes the responsibility of parsing the search property to the author and adds very little overhead to the package.

Add tests

I noticed history didn't have any tests, so I added a few for this change. Happy to add more if needed, it seemed most of the logic was already tested in the index.test file.

Add documentation

For now I just updated the documentation for the createHistory page. Happy to add examples.

@ryanflorence
Copy link
Member

For some context: https://reacttraining.com/blog/reach-react-router-future/

Gonna leave this open as potential API, we do want to be more helpful with search query parsing and encoding in the future, but not ready to work on what it'll look like.

This is great work, thanks for putting in the time, we'll get back to this.

@ryanflorence ryanflorence added the enhancement New feature or request label Sep 5, 2019
@agirton
Copy link
Author

agirton commented Sep 5, 2019

No problem @ryanflorence! Appreciate the context 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants