當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript process.createCommandFactory函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。