Open Hibop opened 6 years ago
const mapStateToProps = (state, ownProps) => { return { active: ownProps.filter === state.visibilityFilter } }
const mapDispatchToProps = ( dispatch, ownProps ) => { return { onClick: () => { dispatch({ type: 'SET_VISIBILITY_FILTER', filter: ownProps.filter }); } }; }
## createStore内部的发布订阅原理 ```js const createStore = (reducer) => { let state; let listeners = []; const getState = () => state; const dispatch = (action) => { state = reducer(state, action); listeners.forEach(listener => listener()); }; const subscribe = (listener) => { listeners.push(listener); return () => { listeners = listeners.filter(l => l !== listener); } }; dispatch({}); return { getState, dispatch, subscribe }; };
https://segmentfault.com/a/1190000012394641
梳理下redux Api
react-redux
const mapDispatchToProps = ( dispatch, ownProps ) => { return { onClick: () => { dispatch({ type: 'SET_VISIBILITY_FILTER', filter: ownProps.filter }); } }; }
《JavaScript 轻量级函数式编程》|《你不知道的JS》姊妹篇
https://segmentfault.com/a/1190000012394641