本文整理汇总了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>();