-
Notifications
You must be signed in to change notification settings - Fork 130
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
Redux integration #9
Comments
you need any help with this? btw terrific job by adopting the ui-router for react! the best solution out there for routing with React |
yeah react-router sucks, if ui-router could integrate with redux plus server side rendering support then the world would been a better place! |
Any updates on this? I'm a long time ui-router user but I'm trying to switch to React and would love to take one of my favorite routers with me! Does anyone have suggestions for integrating the two? Maybe something like neilff/redux-ui-router? Specifically, it'd be nice to use async actions in combination with the ui-router transitions (similar to |
@mheppner Sure! I started working on it: https://github.com/elboman/ui-router-redux The package is not published yet, so you have to build it yourself locally and What it does:
I still have to figure out the last piece, which is triggering transitions using redux actions, because of a circular dependency issue. Because of this, once it's done, the API might change! I'm not set on how to integrate resolves and redux, since everyone uses redux in some different ways. So far this is what I've done: const someState = {
url: '/',
name: 'home',
component: Home,
resolve: [{
token: 'MyData',
deps: ['ApiService', 'store'],
resolveFn: (ApiService, store) => ApiService.getMyData()
.then(data => store.dispatch({ type: 'someType', data }))
}]
} This way the transition waits for the resolve to fetch the data, once fetched, the store dispatches the action and then it goes on with the transition. Once the transition is set and the state component is mounted, the redux store will have the data inside and you can access it from there instead of the This assumes you have available some const appState = {
name: 'app',
abstract: true,
resolve: [
{ token: 'ApiService', resolveFn: () => ApiService },
{ token: 'store', resolveFn: () => store },
],
resolvePolicy: {
when: 'EAGER'
},
component: UIView
} Hope this helps, let me know what you think and if you need any help to set up the redux plugin. |
@elboman great work, this looks promising! 👏 If I was more experienced with react+redux, I'd offer to help, but some of this is a bit over my head right now. |
Package has been released, the repo can be found here: https://github.com/ui-router/redux |
I'd like to discuss a bit what could be a great Redux integration with UI-Router.
NB: There is nothing preventing you from using Redux in combination with the router right now, as you can simply
connect()
your "state component" and that's it.There are some features that I think might be useful:
I'm not a time-travel user so I honestly don't know how many people rely on it but I think it could be supported if it makes sense.
Let me know what you have in mind 😉
The text was updated successfully, but these errors were encountered: