本文整理汇总了TypeScript中typesafe-actions.createAction函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createAction函数的具体用法?TypeScript createAction怎么用?TypeScript createAction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createAction函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createAction
import {createAction} from 'typesafe-actions'
import * as CST from '../../constants'
import {BookmarkTree} from '../../types'
export const addCurrentPage = createAction(
'ADD_CURRENT_PAGE',
(action) => (parentId: string, index: number) => action({parentId, index})
)
export const addSeparator = createAction(
'ADD_SEPARATOR',
(action) => (parentId: string, index: number) => action({parentId, index})
)
export const copyBookmark = createAction('COPY_BOOKMARK', (action) => (id: string) => action({id}))
export const createBookmark = createAction(
'CREATE_BOOKMARK',
(action) => (parentId: string, index: number, title: string, url: string) =>
action({
parentId,
index,
title,
url
})
)
export const createBookmarkAfterId = createAction(
'CREATE_BOOKMARK_AFTER_ID',
(action) => (id: string, title: string, url: string) =>
示例2: createAction
import { createAction } from "typesafe-actions";
import { Project } from "./reducer";
export const fetchProjectsRequest = createAction(
"projects/FETCH_PROJECTS_REQUEST"
);
export const fetchProjectsSuccess = createAction(
"projects/FETCH_PROJECTS_SUCCESS",
resolve => {
return (projects: Project[]) => resolve({ projects });
}
);
export const fetchProjectsError = createAction("projects/FETCH_PROJECTS_ERROR");
示例3: createAction
import {createAction} from 'typesafe-actions'
import {NAV_MODULE} from '../../constants'
export const switchNavModule = createAction(
'SWITCH_NAV_MODULE',
(action) => (navModule: NAV_MODULE) =>
action({
navModule
})
)
示例4: createAction
type?: 'default' | 'success' | 'warning' | 'danger'
}
export interface ITriggerNotificationAction {
type: NotificationsActionTypes.TRIGGER_NOTIFICATION
payload: {
notification: INotification
}
}
export const triggerNotification = createAction(
NotificationsActionTypes.TRIGGER_NOTIFICATION,
resolve => (
notification: ITriggerNotification
) => resolve({
notification: {
id: uuid(),
type: 'default',
...notification,
},
})
)
export interface ICloseNotificationAction {
type: NotificationsActionTypes.CLOSE_NOTIFICATION
payload: {
notificationId: string
}
}
export const closeNotification = (
notificationId: string
示例5: createAction
import {ActionType, createAction, createReducer} from 'typesafe-actions'
export interface WindowsState {
activeWindowId?: string
activeWindowIdQueue: ReadonlyArray<string>
}
export const windowsInitialState: WindowsState = {
activeWindowIdQueue: []
}
export const windowsCreators = {
setActiveWindowId: createAction('SET_ACTIVE_WINDOW_ID', (action) => (windowId: string) =>
action(windowId)),
unsetActiveWindowId: createAction('UNSET_ACTIVE_WINDOW_ID', (action) => (windowId: string) =>
action(windowId))
}
export const windowsReducer = createReducer<WindowsState, ActionType<typeof windowsCreators>>(
windowsInitialState
)
.handleAction(windowsCreators.setActiveWindowId, (state, {payload: windowId}) => {
const activeWindowIdQueue = [
...state.activeWindowIdQueue.filter((x) => x !== windowId),
windowId
]
return {
activeWindowId: activeWindowIdQueue[activeWindowIdQueue.length - 1],
activeWindowIdQueue
}
})
示例6: createAction
import { createAction } from 'typesafe-actions';
import cuid from 'cuid';
import {
ADD_TODO, TOGGLE_TODO, CHANGE_FILTER,
ITodosFilter,
} from './types';
export const addTodo = createAction(ADD_TODO,
(title: string) => ({
type: ADD_TODO,
payload: {
id: cuid(),
title: title,
completed: false,
},
})
);
export const toggleTodo = createAction(TOGGLE_TODO,
(id: string) => ({ type: TOGGLE_TODO, payload: id })
);
export const changeFilter = createAction(CHANGE_FILTER,
(filter: ITodosFilter) => ({ type: CHANGE_FILTER, payload: filter })
);
示例7: Map
import {ActionType, createAction, createReducer, getType} from 'typesafe-actions'
import deleteFromMap from '../../../utils/deleteFromMap'
export interface ListsState {
highlightedIndices: Map<number, number>
itemCounts: Map<number, number>
}
export const listsInitialState: ListsState = {
highlightedIndices: new Map(),
itemCounts: new Map()
}
export const listsCreators = {
removeList: createAction('REMOVE_LIST', (action) => (listIndex: number) => action({listIndex})),
resetLists: createAction('RESET_LISTS'),
setHighlightedIndex: createAction(
'SET_HIGHLIGHTED_INDEX',
(action) => (listIndex: number, itemIndex: number) => action({listIndex, itemIndex})
),
setItemCount: createAction('SET_ITEM_COUNT', (action) => (listIndex: number, itemCount: number) =>
action({listIndex, itemCount})),
unsetHighlightedIndex: createAction(
'UNSET_HIGHLIGHTED_INDEX',
(action) => (listIndex: number, itemIndex: number) => action({listIndex, itemIndex})
)
}
export const listsReducer = createReducer<ListsState, ActionType<typeof listsCreators>>(
listsInitialState,