本文整理匯總了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,