Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 1.46 KB

ReduceReducers.md

File metadata and controls

60 lines (41 loc) · 1.46 KB

reduceReducers

使用Tip

  • 所有的reducer会依次处理同样一个state
  • 需要确保每个reducer处理逻辑没有问题

编写Reducer

Reducer YourReducer01 = ^TheSameState * (id<Action> action, TheSameState *state) {

    if (state == nil) {
    // 需要处理nil 返回初始值
        TheSameState *nextState = [TheSameState new];
        return nextState;
    }

    if ([state isKindOfClass:[TheSameState class]]) {
        // do something
    }

    return state;
};
Reducer YourReducer02 = ^TheSameState * (id<Action> action, TheSameState *state) {

    if (state == nil) {
    	// 需要处理nil 返回初始值
        TheSameState *nextState = [TheSameState new];
        return nextState;
    }

    if ([state isKindOfClass:[TheSameState class]]) {
        // do something
    }

    return state;
};

使用reduceReducers

#import <Redux/Reduce.h>

Reducer reducer = reduceReducers(@[YourReducer01, YourReducer02,...]);
Store *store = [[Store alloc] initWithReducer:reducer
                                      state:nil
                                middlewares:@[middleware01, middleware02, ...]];

Demo

详细内容参见Demo中的ReduceReducers Demo