本文整理汇总了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 };
开发者ID:dojo,项目名称:examples,代码行数:31,代码来源:todoProcesses.ts
示例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>(
开发者ID:dojo,项目名称:widgets,代码行数:31,代码来源:processes.ts
示例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>();
开发者ID:dojo,项目名称:examples,代码行数:14,代码来源:utils.ts
注:本文中的@dojo/framework/stores/process.createCommandFactory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论