本文整理汇总了TypeScript中redux-actions.handleActions函数的典型用法代码示例。如果您正苦于以下问题:TypeScript handleActions函数的具体用法?TypeScript handleActions怎么用?TypeScript handleActions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了handleActions函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: handler
export default <State, Payload, Meta>(handlers: IFlattenReducerMap<State, Payload, Meta>,
initialState?: State) => {
const finalHandlers = _.reduce(
handlers,
(preHandlers, handler: IFlattenReducer<State, Payload, Meta>, actionType: ActionType) => {
return _.assign(preHandlers, {
[String(actionType)]: (state: State, { payload, meta, error }: ActionMeta<Payload, Meta>) => handler(state, payload, meta, error),
});
},
{} as ReducerMap<State, Payload>,
);
return handleActions<State, Payload>(finalHandlers, initialState);
};
示例2: actionHandler
state = actionHandler(0, incrementAction());
const actionHandlerWithReduceMap = ReduxActions.handleAction<number, number>(
'MULTIPLY', {
next(state: number, action: ReduxActions.Action<number>) {
return state * action.payload;
},
throw(state: number) { return state }
},
0
);
state = actionHandlerWithReduceMap(0, multiplyAction(10));
const actionsHandler = ReduxActions.handleActions<number, number>({
'INCREMENT': (state: number, action: ReduxActions.Action<number>) => state + action.payload,
'MULTIPLY': (state: number, action: ReduxActions.Action<number>) => state * action.payload
}, 0);
state = actionsHandler(0, { type: 'INCREMENT' });
const actionsHandlerWithInitialState = ReduxActions.handleActions<number, number>({
'INCREMENT': {
next: (state: number, action: ReduxActions.Action<number>) => state + action.payload,
},
'MULTIPLY': {
next: (state: number, action: ReduxActions.Action<number>) => state * action.payload
}
}, 0);
state = actionsHandlerWithInitialState(0, { type: 'INCREMENT' });
示例3: actionHandler
state = actionHandler(0, incrementAction());
const actionHandlerWithReduceMap = ReduxActions.handleAction<number, number>(
'MULTIPLY', {
next(state: number, action: ReduxActions.Action<number>) {
return state * action.payload;
},
throw(state: number) { return state; }
},
0
);
state = actionHandlerWithReduceMap(0, multiplyAction(10));
const actionsHandler = ReduxActions.handleActions({
INCREMENT: (state: number, action: ReduxActions.Action<number>) => state + action.payload,
MULTIPLY: (state: number, action: ReduxActions.Action<number>) => state * action.payload
}, 0);
state = actionsHandler(0, { type: 'INCREMENT' });
const actionsHandlerWithInitialState = ReduxActions.handleActions({
INCREMENT: {
next: (state: number, action: ReduxActions.Action<number>) => state + action.payload,
},
MULTIPLY: {
next: (state: number, action: ReduxActions.Action<number>) => state * action.payload
}
}, 0);
state = actionsHandlerWithInitialState(0, { type: 'INCREMENT' });
示例4: return
return (dispatch, getState) => {
dispatch(Actions.loadActions.start())
Api.getUser(getState().Auth.token, username)
.then((user) => dispatch(Actions.loadActions.complete(user)))
.catch((err) => dispatch(Actions.loadActions.error(err.message)))
}
},
}
export default handleActions({
[Actions.loadActions.start.toString()]: (state, action) => ({
...state,
loading: true,
}),
[Actions.loadActions.error.toString()]: (state, action) => ({
...state,
error: action.payload,
loading: false,
}),
[Actions.loadActions.complete.toString()]: (state, action) => ({
...state,
user: action.payload,
loading: false,
error: null,
}),
}, {
user: null,
loading: false,
error: null,
})
示例5: require
const handleActions = require("redux-actions").handleActions;
const initialState = {todos: []};
const pendingAction = () => ({inProgress: true, todos: []});
const listAction = (state, action) => ({inProgress: false, todos: action.payload});
export default handleActions({
"ACTION_LIST_PENDING": pendingAction,
"ACTION_LIST_FULFILLED": listAction,
"ACTION_SAVE_PENDING": pendingAction,
"ACTION_SAVE_FULFILLED": listAction,
"ACTION_DELETE_PENDING": pendingAction,
"ACTION_DELETE_FULFILLED": listAction
}, initialState);
示例6: handleActions
export const repository = handleActions(
{
[String(fetchRepos)]: (state: RepositoryState) =>
produce<RepositoryState>(state, draft => {
draft.loading = true;
}),
[String(fetchReposSuccess)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.loading = false;
draft.repositories = action.payload || [];
}),
[String(fetchReposFailed)]: (state: RepositoryState, action: Action<any>) => {
if (action.payload) {
return produce<RepositoryState>(state, draft => {
draft.error = action.payload;
draft.loading = false;
});
} else {
return state;
}
},
[String(deleteRepoFinished)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, (draft: RepositoryState) => {
draft.repositories = state.repositories.filter(repo => repo.uri !== action.payload);
}),
[String(importRepo)]: (state: RepositoryState) =>
produce<RepositoryState>(state, draft => {
draft.importLoading = true;
}),
[String(importRepoSuccess)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, (draft: RepositoryState) => {
draft.importLoading = false;
draft.showToast = true;
draft.toastType = ToastType.success;
draft.toastMessage = `${action.payload.name} has been successfully submitted!`;
draft.repositories = [...state.repositories, action.payload];
}),
[String(importRepoFailed)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
if (action.payload) {
if (action.payload.res.status === 304) {
draft.toastMessage = 'This Repository has already been imported!';
draft.showToast = true;
draft.toastType = ToastType.warning;
draft.importLoading = false;
} else {
draft.toastMessage = action.payload.body.message;
draft.showToast = true;
draft.toastType = ToastType.danger;
draft.importLoading = false;
}
}
}),
[String(closeToast)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.showToast = false;
}),
[String(fetchRepoConfigSuccess)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.repoConfigs = action.payload;
}),
[String(loadConfigsSuccess)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.projectConfigs = action.payload;
}),
[String(loadRepoSuccess)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.currentRepository = action.payload;
}),
[String(loadRepoFailed)]: (state: RepositoryState, action: Action<any>) =>
produce<RepositoryState>(state, draft => {
draft.currentRepository = undefined;
}),
},
initialState
);
示例7: handleActions
export const actions = {
get_unlearn_department_study,
SHOW_ADD_STUDY_MODAL,
add_study,
delete_study,
get_learned_study
}
export default handleActions({
UPDATE_UNLEARNED_STUDY: (state, action) => {
return Object.assign({}, state, {items: action.payload})
},
UPDATE_LEARNED_STUDY: (state, action) => {
return Object.assign({}, state, {items_learned: action.payload})
},
SHOW_ADD_STUDY_MODAL: (state, action) => {
return Object.assign({}, state, {show_study: action.payload})
},
}, {
items: undefined,
show_study: false
})
interface ItemInterface {
publish_time:string,
title:string,
answer:string,
publish_person:string,
checked_by_first:number,
checked_by_second:number,
checked_by_third:number,
示例8: createAction
import { createAction, handleActions } from 'redux-actions'
import { ACTION_TYPES as REF_ACTION_TYPES } from '../../referenceOperations'
import { regionsSettings } from '../../regions/regionsOperations'
export enum ACTION_TYPES {
ANALYTICS_SERVICE = '@ReactiveTraderCloud/ANALYTICS_SERVICE',
}
const INITIAL_STATE = {}
const CURRENCY: string = 'USD'
export const fetchAnalytics = createAction(ACTION_TYPES.ANALYTICS_SERVICE)
export const analyticsServiceEpic = analyticsService$ => action$ => {
return action$.ofType(REF_ACTION_TYPES.REFERENCE_SERVICE)
.flatMapTo(analyticsService$.getAnalyticsStream(CURRENCY))
.map(fetchAnalytics)
}
export const analyticsRegionSettings = regionsSettings('Analytics', 400, 800, false)
export default handleActions({
[ACTION_TYPES.ANALYTICS_SERVICE]: (state, action) => action.payload,
}, INITIAL_STATE)
示例9: dispatch
dispatch(Actions.browse.start())
Api.getTracks(getState().Auth.token)
.then((tracks) => dispatch(Actions.browse.complete(tracks)))
.catch((err) => dispatch(Actions.browse.error(err.message)))
}
},
}
export default handleActions({
[Actions.browse.start.toString()]: (state, action) => ({
...state,
error: null,
loading: true,
}),
[Actions.browse.error.toString()]: (state, action) => ({
...state,
error: action.payload,
loading: false,
}),
[Actions.browse.complete.toString()]: (state, action) => ({
...state,
tracks: action.payload,
error: null,
loading: false,
}),
}, {
loading: false,
error: null,
tracks: [],
})
示例10: createAction
COMPOSITE_STATUS_SERVICE = '@ReactiveTraderCloud/COMPOSITE_STATUS_SERVICE',
}
export const fetchCompositeServiceStatus = createAction(ACTION_TYPES.COMPOSITE_STATUS_SERVICE)
export const compositeStatusServiceEpic = compositeStatusService$ => action$ => {
return action$.ofType(REF_ACTION_TYPES.REFERENCE_SERVICE)
.flatMapTo(compositeStatusService$.serviceStatusStream)
.map(service => getServiceStatus(service))
.map(fetchCompositeServiceStatus)
}
const getServiceStatus = (service) => {
return _.mapValues(service.services, (service: ServiceStatus) => {
return {
isConnected: service.isConnected,
connectedInstanceCount: countInstances(service.instanceStatuses),
serviceType: service.serviceType,
}
})
}
export default handleActions({
[ACTION_TYPES.COMPOSITE_STATUS_SERVICE]: (state, action) => action.payload,
}, {})
export function countInstances(instances) {
return instances
.filter((instance: ServiceInstanceStatus) => instance.isConnected)
.length
}