Methodes
constructor({ns:String, intialState:Object})
/**
* Create an RxStore instance
* @param {Object} opts
* @param {String} opts.ns The namespace of the store. Debuggin purpose. Default: 'rxStore'
* @param {Object} opts.initialState Initial state of the store. Default: {}
*
* @returns {RxStore} A new RxStore instance
*/
constructor({ ns = 'rxStore', initialState = {} } = {})Example
todo.store.js
import RxStore from '@zazapeta/rx-react-store';
const ns = 'Todo';
const initialState = {
todos: []
};
const todoStore = new RxStore({ ns, initialState });
export default todoStore;async dispatch(reducer:Function, ...rest)
Define dispatchers in a dedicated file. Just import todoStore and have access to the dispatch method to update all connected component.
todo.dispatchers.js
createDispatcher(reducer:Function): Function
RxStore provide createDispatcher method to avoid repetitive code.
Define reducers in a dedicated file.
todo.reducers.js
todo.container.jsx
createDispatchers(reducersMap:Object{String,Function}):Object{String, Function}
RxStore provide createDispatchers method to avoid repetitive code.
Define reducers in a dedicated file.
todo.reducers.js
todo.container.jsx
connect(mapStateToProps:Function(state, props)->Object)(BaseComponent:Component):Component
connect is a High Order Component (react-redux.connect). It's create a component that listen for changes comming from the given store.
TIPS: To integrate RxStore with another view library, you may override
connect
todo.container.jsx
Last updated