Redux for BEM projects
You have 2 ways to use it.
- Connect your store with block-container that contains your dynamic logic.
- Create store as singleton without connection with BEM block.
Inherit your block that should be state container from redux-state-container using base-block construction.
Declare (override) you own getInitialState and rootReducer methods (more about reducers).
Use redux store api to interact with your store:
// Dispatch some actions
this.store.dispatch
// Subscribe to the state changes
this.store.subscribe
// Get current state
this.store.getStateYou can use Redux as you want.
Just add redux in your module dependencies and go ahead.
For example, you can define module that provides your store with your logic as singleton.
modules.define('my-store', ['redux'], function(provide, Redux) {
const initialState = { ... };
const rootReducer = (state, action) => { ... };
const store = Redux.createStore(rootReducer, initialState);
provide(store);
});Use this store in needed blocks adding my-store in dependencies.