Flutter与React中的Redux

2018-07-10  本文已影响0人  pj0579

一、Redux的三个原则

二、Flutter和React中Redux的异同点。

const combineReducers = reducers => {
  return (state = {}, action) => {
    return Object.keys(reducers).reduce(
      (nextState, key) => {
        nextState[key] = reducers[key](state[key], action);
        return nextState;
      },
      {} 
    );
  };
};

Flutter中的combineReducers也是通过类似的思想传入特定的action迭代完成。

Reducer<State> combineReducers<State>(Iterable<Reducer<State>> reducers) {
  return (State state, dynamic action) {
    for (final reducer in reducers) {
      state = reducer(state, action);
    }
    return state;
  };
}

三、react-reduxflutter_redux的异同

四、中间件 react-thunkflutter_thunk也是类似的思想,判断Action还是Function执行对应的逻辑。

五、具体参考demo ,https://github.com/xrigau/todo_demo_flutter_redux

上一篇 下一篇

猜你喜欢

热点阅读