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

Dynamic Routing #11

Closed
rsaccon opened this issue Dec 20, 2018 · 6 comments
Labels

Comments

@rsaccon
Copy link
Contributor

@rsaccon rsaccon commented Dec 20, 2018

I want to share one thought of mine about dynamic routing: The most mind-blowing simple but fully functional routing solution (based on window.history) I have seen so far is one written in ReasonML:
Description
Code
Implementation is so much simpler than any of those react router implementations written in Javascript!

The secret sauce is just to split the URL (by /) into a list (ReasonML tail-recursive version of an array, or what in Rust is called Vec) of path segments, than the user of the api can recursively pattern match on that list to do his thing.

I am new to Rust, but it seems to me Rust pattern matching should also allow to do something like that.

@David-OConnor

This comment has been minimized.

Copy link
Member

@David-OConnor David-OConnor commented Dec 20, 2018

Looks great - that's the best routing approach I've seen. The issue that's driving the lack of dynamic routes is related to lifetimes, and where/how to store the popstate-listening closures so we can remove them when adding new ones... The temporary workaround is to create one closure at the start, and never detach it. Need to solve this first. (I think the relevant part of the code you linked is the external removeEventListener : part.)

@rsaccon

This comment has been minimized.

Copy link
Contributor Author

@rsaccon rsaccon commented Dec 20, 2018

yes, at the example, in the didMount app-level life cycle hook, a closure gets registered with the route map and how it has to be processed. And still in that didMount hook, the removeEventListener stuff gets wired up to be run in a closure at component unmount, at:
self.onUnmount(() => ReasonReact.Router.unwatchUrl(watcherID))

@thedodd

This comment has been minimized.

Copy link

@thedodd thedodd commented Jan 25, 2019

I’m super stoked about this framework. The dynamic routing is pretty much the only thing blocking me from being able to fully adopt this for a production app (or at least starting to build it).

@David-OConnor if you (or anyone else) is interested in joining the Rust WASM Working Group, I know a lot of folks would be happy to toss ideas around and do some hacking (myself included).

Weekly, Thursdays. The team repo has more info. Will grab a link.

@David-OConnor

This comment has been minimized.

Copy link
Member

@David-OConnor David-OConnor commented Jan 25, 2019

Added partial dynamic routing in latest commit. See todomvc example. Still need to specify landing page routing, same syntax as before, but now you can push to pages not included in it. Must pass app state down to routing messages, which adds verbosity, but no longer need to recursively call update.

What do y'all think? Any thoughts on dynamic landing pages? Think programmatically setting up the HashMap is enough, or do we need a regex/recursive-pattern-match approach? Maybe I should change the API to be more like that ReasonMl example; it's nicer.

Interested in the group, but won't necessarily be avail Thu.

@David-OConnor David-OConnor pinned this issue Feb 1, 2019
@David-OConnor David-OConnor unpinned this issue Feb 2, 2019
@David-OConnor

This comment has been minimized.

Copy link
Member

@David-OConnor David-OConnor commented Feb 2, 2019

Latest commit has a complete rework of the routing system; it's now like the ReasonML example. I expect this API to stay the same; it's about as simple as it can get. Might have some changes to make internally re how hash and search are handled.

@David-OConnor

This comment has been minimized.

Copy link
Member

@David-OConnor David-OConnor commented Feb 4, 2019

Published in v0.2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.