当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript reducer.loadingReducer函数代码示例

本文整理汇总了TypeScript中@dapps/modules/loading/reducer.loadingReducer函数的典型用法代码示例。如果您正苦于以下问题:TypeScript loadingReducer函数的具体用法?TypeScript loadingReducer怎么用?TypeScript loadingReducer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了loadingReducer函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: switch

export const tokenReducer: Reducer<TokenState> = (
  state = INITIAL_STATE,
  action: TokenReducerAction
): TokenState => {
  switch (action.type) {
    case FETCH_TOKENS_REQUEST:
    case FETCH_POLLS_REQUEST:
    case FETCH_POLL_REQUEST: {
      return {
        ...state,
        loading: loadingReducer(state.loading, action)
      }
    }
    case FETCH_TOKENS_SUCCESS: {
      return {
        loading: loadingReducer(state.loading, action),
        error: null,
        data: toObjectByKey<Token>(action.payload.tokens, state.data, 'address')
      }
    }
    case FETCH_POLLS_SUCCESS: {
      const data = { ...state.data }

      for (const poll of action.payload.polls) {
        if (poll.token) {
          data[poll.token.address] = { ...poll.token }
        }
      }

      return {
        loading: loadingReducer(state.loading, action),
        error: null,
        data
      }
    }
    case FETCH_POLL_SUCCESS: {
      const { token } = action.payload

      return {
        loading: loadingReducer(state.loading, action),
        error: null,
        data: {
          ...state.data,
          [token.address]: { ...token }
        }
      }
    }
    case FETCH_TOKENS_FAILURE:
    case FETCH_POLLS_FAILURE:
    case FETCH_POLL_FAILURE: {
      return {
        ...state,
        loading: loadingReducer(state.loading, action),
        error: action.payload.error
      }
    }
    default:
      return state
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:60,代码来源:reducer.ts


注:本文中的@dapps/modules/loading/reducer.loadingReducer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。