當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript redux-actions.handleActions函數代碼示例

本文整理匯總了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);
};
開發者ID:morlay,項目名稱:redux-actions,代碼行數:14,代碼來源:handleActions.ts

示例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' });
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:redux-actions-tests.ts

示例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' });
開發者ID:VincentDamour,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:redux-actions-tests.ts

示例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,
})
開發者ID:nikteg,項目名稱:loud,代碼行數:30,代碼來源:User.ts

示例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);

開發者ID:rrevanth,項目名稱:adventures-reactive-web-dev,代碼行數:17,代碼來源:reducer.ts

示例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
);
開發者ID:elastic,項目名稱:kibana,代碼行數:76,代碼來源:repository.ts

示例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,
開發者ID:rui19921122,項目名稱:MeetingSystem,代碼行數:30,代碼來源:study.ts

示例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)
開發者ID:tdeheurles,項目名稱:ReactiveTraderCloud,代碼行數:26,代碼來源:analyticsOperations.ts

示例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: [],
})
開發者ID:nikteg,項目名稱:loud,代碼行數:30,代碼來源:Browse.ts

示例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
}
開發者ID:tdeheurles,項目名稱:ReactiveTraderCloud,代碼行數:30,代碼來源:compositeStatusServiceOperations.ts


注:本文中的redux-actions.handleActions函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。