Skip to content

[added] pluggable history implementations #169

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

Closed

Conversation

seanadkinson
Copy link
Contributor

Mostly just cut/paste code into various locations handlers. A nice side-effect is that we could use the memoryHandler for rendering on the server-side I would imagine. Just need to support passing in the currentPath somehow.

All tests should be passing. As @mjackson warned me, I did have some trouble with the tests, but they should all be passing now, and I think the coverage isn't too bad.

This location handler API will make it easy to plug in HistoryJS support now.

closes #166

/**
* Returns the current URL path in from `window.location`, including query string
*/
getWindowPath = function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a named function instead of a global here (i.e. function getWindowPath).

@mjackson
Copy link
Member

mjackson commented Aug 5, 2014

I wonder if we can get rid of the URLStore altogether and just have <Routes> components register/unregister themselves with the various *Location objects as they mount/unmount.

* Location Handler that doesn't actually do any location handling. Instead, requests
* are sent to the server as normal.
*/
var disabledHandler = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name these DisabledLocation, HashLocation, etc. ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. File name as well? I had them packaged in a location directory, so shall I move them up into helpers or just leave em? Will have to do some Git magic if I'm just changing the letter casing 👊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's stick them in helpers.

I think git mv -f should do the trick. :)

@ryanflorence
Copy link
Member

if we are providing a new api to supply your own history implementation, we should change the commit message subject to [added] pluggable history implementations, if we have not yet exposed an API, then we don't want it in the changelog since its not relevant to the API, so remove the [fixed] :)

@ryanflorence
Copy link
Member

(if there is a new API, I'll document it, no need for docs in this commit unless you feel like it)

@seanadkinson
Copy link
Contributor Author

Sure, I'll change to [added] since yes, I think you could say it is providing a new API for adding history implementations.

Side note: it could be worth documenting the memory and disabled options, since someone may have some use for them, not sure. I really think the memory option will make server-side rendering easier, but I haven't really been too involved in that discussion and still need to read the thread.

I'll make the changes recommended and rebase and squash into a single commit a little later tonight.

@seanadkinson
Copy link
Contributor Author

Alright, squashed and pushed an [added] commit. I moved the files up out of locations, and named them HashLocation.js, HistoryLocation.js, etc, and changed the getWindowPath() function declaration.

@mjackson I just saw your comment above about removing URLStore altogether. I still think that the URLStore class serves a good purpose, namely being a "store" in the normal sense. It would be a shame to pollute the location instances with registration and setup validation the way URLStore currently does. I'd vote to keep it myself.

@@ -0,0 +1,10 @@
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the "s" off and name this file modules/helpers/Location.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, I switched the filename and variable names to Location.

The vars got a little interesting in URLStore though, where there is already location (lowercase) being passed into setup() as a string, and now Location (uppercase) which is the map from name to handler. I wanted to stomp out all references to "handler", but since there was already a _location (the string), I left _locationHandler there to distinguish the difference.

Suggestions welcome if this is a little too messy.

@ryanflorence
Copy link
Member

Lazy lazy lazy.

Lazy would be not doing anything here :P Keep it up!

@seanadkinson
Copy link
Contributor Author

Pushed fixes, build should be green now!

@seanadkinson seanadkinson changed the title [fixed] Refactored URLStore into multiple implementations [added] Refactored URLStore into multiple implementations Aug 6, 2014
@ryanflorence
Copy link
Member

how about [added] pluggable history implementations the fact it was refactored is irrelevant to the API

@seanadkinson seanadkinson changed the title [added] Refactored URLStore into multiple implementations [added] pluggable history implementations Aug 6, 2014
@seanadkinson
Copy link
Contributor Author

Updated the PR name. Do I need to reword the commit message as well? Or does the release notes just read from the PR name?

@ryanflorence
Copy link
Member

just the subject, talking about the refactoring is valuable in the commit message though :)

@ryanflorence
Copy link
Member

Oh, I misunderstood, yeah, you need to reword the commit to change the subject, it doesn't use the pull request subject.

@seanadkinson
Copy link
Contributor Author

Commit message updated.

@ryanflorence
Copy link
Member

thanks for going through the trouble :) viewers of the changelog will thank you.

@seanadkinson
Copy link
Contributor Author

Pushed fix for merge conflicts. Added /Location.js which includes /modules/helpers/Location.js, following the pattern of the other public modules.

@ryanflorence
Copy link
Member

@mjackson I'm 👍 if you are. Merge at will!

@ryanflorence
Copy link
Member

I just realized we could make a TestHistory module to help with a lot of integration tests between parts of the library.

@mjackson
Copy link
Member

@rpflorence That was the idea behind the MemoryLocation.

@ryanflorence
Copy link
Member

@mjackson you ready to merge this (fix conflicts first, ofc)?

mjackson added a commit that referenced this pull request Aug 13, 2014
Adds the ability to specify <Routes location={HashLocation}> instead
of just using a string. Also, use Browserify's events module instead
of event-emitter.

Also, replaces URLStore with PathStore which takes a location object
instead of using a string to identify which location it's using.
@mjackson
Copy link
Member

I added a few of my own touches, rebased, and merged manually.

Thanks for your work on this @seanadkinson! :D

@mjackson mjackson closed this Aug 13, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
brophdawg11 pushed a commit that referenced this pull request Mar 27, 2024
This is kinda big but opens up a lot of use cases,

- can build better pending navigation UI with useTransition telling app more detailed information (state, type)
- replaces usePendingFormSubmit and usePendingLocation
- actually aborts stale submissions/loads
- fixes bugs around interrupted submissions/navigations
- actions can return data now
- super useful for form validation, no more screwing around with sessions
- allows apps to call loaders and actions outside of navigation
- manages cancellation of stale submissions and loads
- reloads route data after actions
- commits the freshest reloaded data along the way when there are multiple inflight

allows route modules to decide if they should reload or not

- after submissions
- when the search params change
- when the same href is navigated to

other stuff

- reloads route data when the same href is navigated to
- does not create ghost history entries on interrupted navigation

These old hooks still work, but have been deprecated for the new hooks.

- useRouteData -> useLoaderData
- usePendingFormSubmit -> useTransition().submission
- usePendingLocation -> useTransition().location

Also includes a helping of docs updates

Closes #169, #151, #175, #128, #54, #208
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URLStore should be refactored and pluggable
3 participants