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

where to init redux store #81

Open
ShockiTV opened this issue Feb 12, 2016 · 5 comments
Open

where to init redux store #81

ShockiTV opened this issue Feb 12, 2016 · 5 comments

Comments

@ShockiTV
Copy link

Hello,
I managed to use redux to keep state of my autogenerated navigation.
Navigation is in core module.
Store is initialized in client/config/context.js.
Test repo https://github.com/ShockiTV/mantra-test .

Question is where is best place to init store ?
Prepare it in separate file in client/config and import it in client/config/context.js from where it get exported to that kinda global app context?
So in theory same way how I am doing, just put it in separate file ?

@arunoda
Copy link
Collaborator

arunoda commented Feb 12, 2016

I think you are doing it partially correct.
It should go into the context.

But, you need to write your reducers inside the module.
So, in the mainjs combine all reducers, (required from each module)

Then pass that rootReducer to the initContext() and use that to create the store.

@lsunsi
Copy link

lsunsi commented Feb 23, 2016

in a somewhat related question, where should I put my reducers inside a module?
I thought either I should put them in 'actions' folder or I should create a 'reducers' folder

@ShockiTV
Copy link
Author

I put them into configs for now https://github.com/ShockiTV/mantra-sample-blog-app/tree/redux

@ghost
Copy link

ghost commented Mar 3, 2016

@lsunsi it probably depends on the complexity of your project, but I think it's a good idea to separate your actions and reducers into separate directories.

@haizi-zh
Copy link

haizi-zh commented Apr 20, 2016

@ShockiTV 's example is quite inspiring, but it seems incomplete. The reducers and stores are not bind to React components yet, and there's no usage of Provider and connect. Therefore, based on the original mantra-sample-blog-app, I built a new demo, which shows how Redux may be used together with mantra.

https://github.com/haizi-zh/mantra-sample-blog-app

In summary:

  • I extend the main class App from mantra-core. Now it can collect Redux reducers from various modules via loadModule. During init, it combines these reducers, creates a Redux store, and put it in the context object (the key is ReduxStore). This is pretty much like how routes functions work in the original App implementation.
  • In the Redux container, I use composeAll to get a full-function Redux container component.

Wish this can help!

Update: I've also submitted a pull request regarding this:
mantrajs/mantra-core#3

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

No branches or pull requests

4 participants