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

async import state #40

Open
mtsewrs opened this issue Jan 19, 2017 · 13 comments
Open

async import state #40

mtsewrs opened this issue Jan 19, 2017 · 13 comments

Comments

@mtsewrs
Copy link

mtsewrs commented Jan 19, 2017

I have specific stores for some routes, would it be possible to requires those async? I know it's possible with redux. Maybe pass the store to react-router? I'll se what I can do

@foxhound87
Copy link
Owner

I see that redux has some async feature (actions/flow) but it is to load data asynchronously. I think you want to enable lazyloading / webpack code splitting for stores, but I'm not sure it can be possible with the current RFX stores structure. For example I see that with redux is possible to lazyload reducers. Maybe in RFX we may lazyload actions but they must be decoupled from stores.

@mtsewrs
Copy link
Author

mtsewrs commented Jan 22, 2017

I figured as much, seems to be a mobx thing then. I'll close this then.

@mtsewrs mtsewrs closed this as completed Jan 22, 2017
@foxhound87
Copy link
Owner

If you have an implementation please share it.
I will deepen it, I think we can accomplish this enhancing the stack with a new and better routing system, maybe mobx-router but still lack of SSR support and code splitting. Would be cool to implement these features. Right now I think react-router is not the perfect solution when working with mobx.

@mtsewrs
Copy link
Author

mtsewrs commented Jan 22, 2017

I would be pretty dope to do that and also save a few bytes.

Yeah I got it working after a couple of minutes, but it's not pretty... Something like this:

export default store => (
  <Route path="/" component={AppLayout}>

    <IndexRoute
      getComponent={(loc, cb) => {
      import('./stores/home').then(module => store.home = module.default);
      return $import(loc, cb, 'Home')
     }}
    />

  etc....

  </Route>
)

I'll play with it more tomorrow!

@mtsewrs mtsewrs reopened this Jan 22, 2017
@mtsewrs
Copy link
Author

mtsewrs commented Jan 22, 2017

The problem I'm trying to solve know is ssr...

@mtsewrs
Copy link
Author

mtsewrs commented Jan 22, 2017

@foxhound87 It can be done with react-router but it's not optimal. I will probably use it but maybe implement it when mobx-router has support for ssr and code splitting? Have you tried it?

@foxhound87
Copy link
Owner

Not yet, but when mobx-router will be ready

@pdfowler
Copy link
Contributor

pdfowler commented Feb 2, 2017

I'm still feeling my way around react/mobx/etc, but it seems like the (controversial) react-router v4 makes it possible to address all these things simultaneously. I read through this article , and it seems that you can hit all requirements with the new version. Any thoughts on migrating to react-router v4?

@foxhound87
Copy link
Owner

Thank you for the article.

In the meanwhile mobx-router reaches SSR and async functionalities, the main libs like react-router have to be upgraded anyway.

I can make a new branch for those who want to contribute.

@mtsewrs
Copy link
Author

mtsewrs commented Feb 3, 2017

I'd be happy to help

@foxhound87
Copy link
Owner

Great @mattiasewers !

Made it: https://github.com/foxhound87/rfx-stack/tree/react-router-4

@mtsewrs
Copy link
Author

mtsewrs commented Mar 11, 2017

Now that react router v4 is released, their documentation said this about code-splitting and server-side rendering.

Code-splitting + server rendering
We’ve tried and failed a couple of times.
Godspeed those who attempt the server-rendered, code-split apps.

Tbh I havent't tried v4 yet but it seems like react-router might be a hack for this stack. So stick with v3 until mobx-router is ready or something else or try to implement v4? What do guys think?

@foxhound87
Copy link
Owner

At this point doesn't worth the effort for this upgrade, at least until those functionalities will be officially supported (but it seems very unlikely).

Let's see the mobx-router future development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants