本文整理汇总了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
}
}