如何通过单个操作删除每个Reducer中的状态

时间:2018-07-24 12:43:54

标签: javascript angular reducers ngrx-store

我有10个reducer,并且我想删除每个reducer中的状态值 一次点击,该如何实现?

2 个答案:

答案 0 :(得分:2)

我认为重置历史记录的最直接方法是创建一个动作,这10个reducer会监听这些声音,当它们发生时,它们会相应地重置其状态。这是一个示例:

@Override void onReceive(Context context, Intent intent) {
    String arg = intent.getExtras().getString("the key used in putExtra");
    // do something with the argument

    //or, launch an activity and pass that argument
    Intent activityIntent = new Intent(context, YourActivity.class);
    intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
    activityIntent.putExtras(intent.getExtras());
    context.startActivity(activityIntent);
}

减速器1

class ResetState extends Action {
  readonly type = "RESET_STATE"
}

减速器2

function reducer1(state, action){
  switch(action.type) {
    case "RESET_STATE":
      return {};
  }
}

答案 1 :(得分:0)

您可以像这样创建metaReducer。

export function clearData(reducer: ActionReducer<any>): ActionReducer<any> {
    return function (state, action) {

        switch (action.type) {
            case CLEAR_DATA:
                state = undefined;
        }

        return reducer(state, action);
    };
}

并将其包含在您的metaReducers数组中,该数组最终将被馈送到功能模块中的StoreModule初始化。