You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@kitze and other contributors, thanks for this awesome project! I spent my whole day yesterday switching over a significant application from react-router to mobx-router. I was having subtle data loading issues with react-router, which are now gone by taking the pure state-driven approach by mobx-router.
I'd like to share a couple of experiences when porting over to mobx-router and also a few questions. Hope these will help improve the documentation for future users.
Name of the root store
It was not clear from the docs that mobx-router expects the name store for the MobX store supplied to the Provider. I initially tried to use a more descriptive name like this: <Provider rootStore={rootStore}>, which did not work and was difficult to debug because of obscure error messages.
Usage of root store
I am not entirely sure how the mobx-router uses the store and why it needs the entire root store instead of just its own RouterStore? If the idea was to expose the entire rootStore to it, then why does the goTo() method require a store parameter? mobx-router should be able to use the root store that it knows about.
class RootStore {
constructor() {
this.userStore = new UserStore(this);
this.todoStore = new TodoStore(this);
}
}
Extending this example, I think it makes sense to pass the root store to the RouterStore like this:
class RootStore {
constructor() {
this.userStore = new UserStore(this);
this.todoStore = new TodoStore(this);
this.routerStore = new RouterStore(this);
}
}
I used the name this.routerStore instead of this.router to clearly make the distinction between the router vs. the router store.
Passing root store to mobx-router
I assume that the official place to hand off the rootStore to the mobx-router is the call to startRouter, is this correct?
startRouter(views, store);
Also IMHO, the first parameter should be called routes - what we are passing in is a map of routes, not views. This will immensely clarify the usage pattern for newbies.
Thanks in advance for your thoughts on these questions and suggestions.
I am really excited to contribute back to this project. @kitze, I see that the last commit to this repo was back in August. I am sure you are busy, but any idea when you are going to be active again? Thanks for this wonderful work!
The text was updated successfully, but these errors were encountered:
I would also change the mobx router api so that the constructor of routerStore accepts the rootStore.
The value provided in the constructor of the rootstore can then be used when calling goTo instead of having to pass the entire rootStore each time we call goTo from somewhere in the application.
@kitze and other contributors, thanks for this awesome project! I spent my whole day yesterday switching over a significant application from react-router to mobx-router. I was having subtle data loading issues with react-router, which are now gone by taking the pure state-driven approach by mobx-router.
I'd like to share a couple of experiences when porting over to mobx-router and also a few questions. Hope these will help improve the documentation for future users.
Name of the root store
It was not clear from the docs that mobx-router expects the name
store
for the MobX store supplied to theProvider
. I initially tried to use a more descriptive name like this:<Provider rootStore={rootStore}>
, which did not work and was difficult to debug because of obscure error messages.Usage of root store
I am not entirely sure how the mobx-router uses the
store
and why it needs the entire root store instead of just its own RouterStore? If the idea was to expose the entire rootStore to it, then why does thegoTo()
method require astore
parameter? mobx-router should be able to use the root store that it knows about.Creation of the root and router stores
Following the pattern described in MobX documentation, I generally define a root store like this:
Extending this example, I think it makes sense to pass the root store to the RouterStore like this:
I used the name
this.routerStore
instead ofthis.router
to clearly make the distinction between the router vs. the router store.Passing root store to mobx-router
I assume that the official place to hand off the rootStore to the mobx-router is the call to
startRouter
, is this correct?Also IMHO, the first parameter should be called
routes
- what we are passing in is a map of routes, not views. This will immensely clarify the usage pattern for newbies.Thanks in advance for your thoughts on these questions and suggestions.
I am really excited to contribute back to this project. @kitze, I see that the last commit to this repo was back in August. I am sure you are busy, but any idea when you are going to be active again? Thanks for this wonderful work!
The text was updated successfully, but these errors were encountered: