-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
programmatic routing #1101
Comments
I'm not a huge fan of outright supporting unstructured route setting more than already exists, but I am a big fan of improving the ergonomics of setting routes. I might explore in the future having a method that exists on Switch so you can set the route without fiddling with creating dispatchers and sending the proper message type. For example: let new_route = AppRoute::SomeVariant{user_id: 4};
new_route.set_route_via_agent();
let new_route = AppRoute::SomeVariant{user_id: 5};
new_route.replace_route_via_agent(); |
Being able to programmatically "go to" an instance of your application switch would be just fine for me, and it feels much more ergonomic. I don't think we need the |
I do think there needs to be some indicator through which it communicates the means through which the route change happens, otherwise it appears to be too "magical". I agree that Maybe instead: RouteAgentDispatcher::set_route(AppRoute::SomeVariant);
RouteAgentDispatcher::replace_route(AppRoute::SomeVariant); A little more verbose, but gets the point across much more cleanly. Thoughts? |
I would like to continue the discussion on this as there have been numerous users with the same problem. Having these associated methods on the |
What about the way router_link does it? It doesn't feel too verbose to me (perhaps just me) and avoids hard-coding route strings. fn update(&mut self, msg: Self::Message) -> ShouldRender {
// ...
Msg::MessageThatChangesRoute => {
self.router.send(RouteRequest::ChangeRoute(AppRoute::OtherRoute.into()));
false
},
// ..
} |
Perhaps there are some ideas in this fork that I've been hacking away on that could be brought upstream? https://github.com/kellpossible/switch-router/blob/master/src/service/mod.rs |
I ended up with code like this within callbacks:
It works, but it feels like a lot of boilerplate. Would it be possible to hide this all behind an API something like:
I'm not sure if it should live on
Router
. But some statically accessible thing that lets us programmatically change route without needing to know all the innards. We probably need one static method for each of theRouteRequest
verbs.The text was updated successfully, but these errors were encountered: