本文整理匯總了TypeScript中@dojo/framework/stores/process.createCommandFactory函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createCommandFactory函數的具體用法?TypeScript createCommandFactory怎麽用?TypeScript createCommandFactory使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createCommandFactory函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: commandFactory
import { createCommandFactory, createProcess } from '@dojo/framework/stores/process';
import { PatchOperation } from '@dojo/framework/stores/state/Patch';
import { add, remove, replace } from '@dojo/framework/stores/state/operations';
import { uuid } from '@dojo/framework/core/util';
export type TodoStore = {
completedCount: number;
completed: boolean;
currentSearch: string;
currentTodo: string;
editedTodo: Todo | undefined;
todoCount: number;
todos: Todos;
};
const commandFactory = createCommandFactory<TodoStore>();
export interface Todo {
id: string;
label: string;
completed?: boolean;
editing?: boolean;
}
export interface Todos {
[key: string]: Todo;
}
const addTodoCommand = commandFactory(({ get, path }): PatchOperation[] => {
const id = uuid();
const todo = { label: get(path('currentTodo')).trim(), id };
示例2: Error
import { createProcess, createCommandFactory, Process } from '@dojo/framework/stores/process';
import { replace, remove } from '@dojo/framework/stores/state/operations';
import {
FetcherResult,
GridState,
FetcherCommandPayload,
PageChangeCommandPayload,
SortCommandPayload,
FilterCommandPayload,
UpdaterCommandPayload
} from './interfaces';
const commandFactory = createCommandFactory<GridState>();
const pageChangeCommand = commandFactory<PageChangeCommandPayload>(({ path, get, payload: { id, page } }) => {
const currentPage = get(path(id, 'meta', 'page'));
if (page !== currentPage) {
return [replace(path(id, 'meta', 'page'), page)];
}
return [];
});
const preFetcherCommand = commandFactory<PageChangeCommandPayload>(({ path, get, payload: { id, page } }) => {
const fetchedPages = get(path(id, 'meta', 'fetchedPages')) || [];
if (fetchedPages.indexOf(page) === -1) {
return [replace(path(id, 'meta', 'fetchedPages'), [...fetchedPages, page])];
}
throw Error('The page has already been requested');
});
const fetcherCommand = commandFactory<FetcherCommandPayload>(
示例3: getHeaders
import { createCommandFactory } from '@dojo/framework/stores/process';
import { State } from '../interfaces';
export function getHeaders(token?: string): any {
const headers: { [key: string]: string } = {
'Content-Type': 'application/json'
};
if (token) {
headers['Authorization'] = `Token ${token}`;
}
return headers;
}
export const commandFactory = createCommandFactory<State>();