访问减速器文件

时间:2018-10-26 00:54:28

标签: redux react-redux-i18n

我有一个Reducer文件,如下所示:

const communication: Reducer<CommunicationState> = (state: CommunicationState = initState,
                                                action: IAction): CommunicationState => {
  switch (action.type) {
    case ActionTypes.GET_REQUEST_BEGIN:
    return state.addToAsyncCalls();
    case ActionTypes.GET_REQUEST_FAILURE: {
    const errorText = action.payload;
    return state.removeFromAsyncCalls();
   }
   case ActionTypes.GET_REQUEST_SUCCESS:
   return state.removeFromAsyncCalls();
   default:
   return state;
  }
 };

 export default communication;

这是状态文件:

export interface ICommunicationState {
 numberOfRequests: number; 
}

const initialCommunicationState: ICommunicationState = {
  numberOfRequests: 0
};

export class CommunicationState extends Immutable.Record(initialCommunicationState) implements ICommunicationState {

  public readonly numberOfRequests: number;

  public addToAsyncCalls(): CommunicationState {
     return this.set("numberOfRequests", this.numberOfRequests + 1) as CommunicationState;
  } 

  public removeFromAsyncCalls(): CommunicationState {
     return this.set("numberOfRequests", this.numberOfRequests - 1) as CommunicationState;
   }

这2种方法跟踪尚未完成的请求。我的API调用有几个文件。是否可以从任何文件访问上述2个文件,以便我可以跟踪numberOfRequests的当前值?

0 个答案:

没有答案