Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a practical architecture of Meteor projects, it would be great if mantra provides a standard way of integrating Redux into mantra projects. The mantra guide does mention that we can manage applications' local states via Redux [ref]. Unfortunately, up till now, there are no "official" and easy ways of doing so in mantra.
Therefore, I have extended the
mantra-core
package to include Redux support.First of all, a module might contain the definition of an map of reducer functions:
When the
App
instance "loads" the module byloadModule
, as well as dealing with routes and actions, it also collects the module's reducers and adds them toapp._reducers
.After all modules have been loaded, in
init()
, theApp
tries to combine the reducers, and from which a Redux store is created afterwards. The store will be added to the context, namedReduxStore
.For Redux containers to access the store, I use
Provider
andconnect
from thereact-redux
package to bind React, Redux and mantra together. All these behaviours are implemented in thewithRedux
function.Imagine we want to build a Redux container, which maps the app's state to props and provide them to its children presentation components. We can do it easily with just one line of code:
Then we can happily use the container:
I've forked
mantra-sample-blog-app
and added a Redux counter component to it, which may serve as a demo of the integration of Redux into mantra projects:https://github.com/haizi-zh/mantra-sample-blog-app/tree/new-mantra-core/client/modules/redux_demo