当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript process.createProcess函数代码示例

本文整理汇总了TypeScript中@dojo/framework/stores/process.createProcess函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createProcess函数的具体用法?TypeScript createProcess怎么用?TypeScript createProcess使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createProcess函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: commandFactory

import { createProcess } from '@dojo/framework/stores/process';
import { replace } from '@dojo/framework/stores/state/operations';
import { commandFactory } from './utils';
import { baseUrl } from '../config';

const getTagsCommand = commandFactory(async ({ path }) => {
	const response = await fetch(`${baseUrl}/tags`);
	const json = await response.json();

	return [replace(path('tags'), json.tags)];
});

export const getTagsProcess = createProcess('get-tags', [getTagsCommand]);
开发者ID:dojo,项目名称:examples,代码行数:13,代码来源:tagProcesses.ts

示例2: get

	if (index !== -1) {
		return [remove(at(path('article', 'comments'), index))];
	}
	return [];
});

const newCommentInputCommand = commandFactory<NewCommentPayload>(({ path, payload: { newComment } }) => {
	return [replace(path('article', 'newComment'), newComment)];
});

const deleteArticleCommand = commandFactory<SlugPayload>(async ({ get, path, payload: { slug } }) => {
	const token = get(path('user', 'token'));
	await fetch(`${baseUrl}/articles/${slug}`, {
		method: 'delete',
		headers: getHeaders(token)
	});
	return [];
});

export const getArticleProcess = createProcess('get-article', [
	startLoadingArticleCommand,
	[loadArticleCommand, loadCommentsCommand]
]);
export const deleteCommentProcess = createProcess('delete-comment', [deleteCommentCommand]);
export const addCommentProcess = createProcess('add-comment', [addCommentCommand]);
export const newCommentInputProcess = createProcess('new-comment-input', [newCommentInputCommand]);
export const favoriteArticleProcess = createProcess('fav-article', [favoriteArticleCommand]);
export const followUserProcess = createProcess('follow-user', [followUserCommand]);
export const deleteArticleProcess = createProcess('delete-article', [deleteArticleCommand]);
开发者ID:dojo,项目名称:examples,代码行数:29,代码来源:articleProcesses.ts

示例3: async

const updaterCommand = commandFactory<UpdaterCommandPayload>(
	async ({ at, path, get, payload: { id, updater, columnId, value, page, rowNumber } }) => {
		const item = get(at(path(id, 'data', 'pages', `page-${page}`), rowNumber));
		try {
			await updater(item);
		} catch (err) {
			const previousItem = get(path(id, 'meta', 'editedRow', 'item'));
			return [replace(at(path(id, 'data', 'pages', `page-${page}`), rowNumber), previousItem)];
		}

		return [replace(path(id, 'meta', 'editedRow'), undefined)];
	}
);

export const updaterProcess: Process<GridState, UpdaterCommandPayload> = createProcess('grid-update', [
	preUpdateCommand,
	updaterCommand
]);
export const fetcherProcess: Process<GridState, FetcherCommandPayload> = createProcess('grid-fetch', [
	preFetcherCommand,
	fetcherCommand
]);
export const filterProcess: Process<GridState, FilterCommandPayload> = createProcess('grid-filter', [
	preFilterCommand,
	filterCommand
]);
export const sortProcess: Process<GridState, SortCommandPayload> = createProcess('grid-sort', [
	preSortCommand,
	sortCommand
]);
export const pageChangeProcess: Process<GridState, PageChangeCommandPayload> = createProcess('grid-page-change', [
	pageChangeCommand
开发者ID:dojo,项目名称:widgets,代码行数:32,代码来源:processes.ts

示例4: commandFactory

const updateUserSettingsCommand = commandFactory(async ({ path, get }) => {
	const token = get(path('user', 'token'));
	const requestPayload = get(path('settings'));
	const response = await fetch(`${baseUrl}/user`, {
		method: 'put',
		headers: getHeaders(token),
		body: JSON.stringify(requestPayload)
	});

	const json = await response.json();

	return [
		replace(path('user'), json.user),
		replace(path('settings'), { loaded: false, loading: false }),
		replace(path('routing', 'outlet'), 'user'),
		replace(path('routing', 'params'), { username: get(path('settings', 'username')) })
	];
});

export const getUserSettingsProcess = createProcess('user-settings', [
	startUserSettingsCommand,
	getUserSettingsCommand
]);
export const updateUserSettingsProcess = createProcess('update-user-settings', [updateUserSettingsCommand]);
export const usernameInputProcess = createProcess('username-input', [usernameInputCommand]);
export const emailInputProcess = createProcess('email-input', [emailInputCommand]);
export const passwordInputProcess = createProcess('password-input', [passwordInputCommand]);
export const bioInputProcess = createProcess('bio-input', [bioInputCommand]);
export const imageUrlInputProcess = createProcess('image-url-input', [imageUrlInputCommand]);
开发者ID:dojo,项目名称:examples,代码行数:29,代码来源:settingsProcesses.ts

示例5: replace

	return [ replace(path('currentSearch'), search) ];
});

const initialStateCommand = commandFactory(({ path }) => {
	return [
		add(path('completedCount'), 0),
		add(path('completed'), false),
		add(path('currentSearch'), ''),
		add(path('currentTodo'), ''),
		add(path('editedTodo'), undefined),
		add(path('todoCount'), 0),
		add(path('todos'), {})
	];
});

export const initialStateProcess = createProcess('initial-state', [ initialStateCommand ]);

export const addTodoProcess = createProcess('add-todo', [ addTodoCommand, updateTodoCountsCommand, updateCompletedFlagCommand ]);

export const removeTodoProcess = createProcess('remove-todo', [ removeTodoCommand, updateTodoCountsCommand, updateCompletedFlagCommand ]);

export const toggleTodoProcess = createProcess('toggle-todo', [ toggleTodoCommand, updateTodoCountsCommand, updateCompletedFlagCommand ]);

export const toggleTodosProcess = createProcess('toggle-todos', [ toggleTodosCommand, updateTodoCountsCommand, updateCompletedFlagCommand ]);

export const editTodoProcess = createProcess('edit-todo', [ editTodoCommand ]);

export const clearCompletedProcess = createProcess('clear-completed', [ clearCompletedCommand, updateTodoCountsCommand, updateCompletedFlagCommand ]);

export const saveTodoProcess = createProcess('save-todo', [ saveTodoCommand ]);
开发者ID:dojo,项目名称:examples,代码行数:30,代码来源:todoProcesses.ts

示例6: replace

		const json = await response.json();
		return [
			replace(path('feed', 'items'), json.articles),
			replace(path('feed', 'total'), json.articlesCount),
			replace(path('feed', 'offset'), offset),
			replace(path('feed', 'loading'), false),
			replace(path('feed', 'loaded'), true)
		];
	}
);

const favoriteFeedArticleCommand = commandFactory<FavoriteArticlePayload>(
	async ({ at, get, path, payload: { slug, favorited } }) => {
		const token = get(path('user', 'token'));
		const response = await fetch(`${baseUrl}/articles/${slug}/favorite`, {
			method: favorited ? 'delete' : 'post',
			headers: getHeaders(token)
		});
		const json = await response.json();
		const index = getItemIndex(get(path('feed', 'items')), slug);

		if (index !== -1) {
			return [replace(at(path('feed', 'items'), index), json.article)];
		}
		return [];
	}
);

export const fetchFeedProcess = createProcess('fetch-feed', [startFetchingFeedCommand, fetchFeedCommand]);
export const favoriteFeedArticleProcess = createProcess('fav-feed-article', [favoriteFeedArticleCommand]);
开发者ID:dojo,项目名称:examples,代码行数:30,代码来源:feedProcesses.ts

示例7: replace

import { createProcess } from '@dojo/framework/stores/process';
import { replace } from '@dojo/framework/stores/state/operations';
import { commandFactory } from './utils';
import { ChangeRoutePayload } from './interfaces';

const changeRouteCommand = commandFactory<ChangeRoutePayload>(({ path, payload: { outlet, context } }) => {
	return [
		replace(path('routing', 'outlet'), outlet),
		replace(path('routing', 'params'), context.params),
		replace(path('settings', 'loaded'), false),
		replace(path('profile', 'loaded'), false),
		replace(path('feed', 'loaded'), false),
		replace(path('feed', 'category'), undefined),
		replace(path('editor', 'loaded'), false),
		replace(path('errors'), {})
	];
});
export const changeRouteProcess = createProcess('change-route', [changeRouteCommand]);
开发者ID:dojo,项目名称:examples,代码行数:18,代码来源:routeProcesses.ts

示例8: replace

			replace(path('user'), {})
		];
	}

	global.sessionStorage.setItem('conduit-session', JSON.stringify(json.user));

	return [
		replace(path('routing', 'outlet'), 'home'),
		replace(path('register', 'loading'), false),
		replace(path('errors'), undefined),
		replace(path('user'), json.user),
		replace(path('feed', 'items'), undefined),
		replace(path('feed', 'loaded'), false)
	];
});

const logoutCommand = commandFactory(({ path }) => {
	global.sessionStorage.removeItem('conduit-session');
	return [replace(path('user'), {}), replace(path('routing', 'outlet'), 'home')];
});

export const loginProcess = createProcess('login', [startLoginCommand, loginCommand, clearLoginInputs]);
export const registerProcess = createProcess('register', [startRegisterCommand, registerCommand, clearRegisterInputs]);
export const loginEmailInputProcess = createProcess('login-email-input', [loginEmailInputCommand]);
export const loginPasswordInputProcess = createProcess('login-password-input', [loginPasswordInputCommand]);
export const registerEmailInputProcess = createProcess('register-email-input', [registerEmailInputCommand]);
export const registerPasswordInputProcess = createProcess('register-password-input', [registerPasswordInputCommand]);
export const registerUsernameInputProcess = createProcess('register-username-input', [registerUsernameInputCommand]);
export const setSessionProcess = createProcess('set-session', [setSessionCommand]);
export const logoutProcess = createProcess('logout', [logoutCommand]);
开发者ID:dojo,项目名称:examples,代码行数:30,代码来源:loginProcesses.ts

示例9: fetch

	};

	const url = slug ? `${baseUrl}/articles/${slug}` : `${baseUrl}/articles`;
	const response = await fetch(url, {
		method: slug ? 'put' : 'post',
		headers: getHeaders(token),
		body: JSON.stringify(requestPayload)
	});
	const json = await response.json();

	if (!response.ok) {
		return [replace(path('editor', 'loading'), false), replace(path('errors'), json.errors)];
	}

	return [
		replace(path('article', 'item'), json.article),
		replace(path('article', 'loaded'), true),
		replace(path('editor'), undefined)
	];
});

export const titleInputProcess = createProcess('title-input', [titleInputCommand]);
export const descInputProcess = createProcess('desc-input', [descriptionInputCommand]);
export const bodyInputProcess = createProcess('body-input', [bodyInputCommand]);
export const tagInputProcess = createProcess('tag-input', [tagInputCommand]);
export const addTagProcess = createProcess('add-tag', [addTagCommand, clearTagInputCommand]);
export const removeTagProcess = createProcess('remove-tag', [removeTagCommand]);
export const getEditorArticleProcess = createProcess('get-editor-article', [getArticleForEditorCommand]);
export const publishArticleProcess = createProcess('publish-article', [startPublishCommand, publishArticleCommand]);
export const clearEditorProcess = createProcess('clear-editor', [clearEditorCommand]);
开发者ID:dojo,项目名称:examples,代码行数:30,代码来源:editorProcesses.ts

示例10: get

const followUserCommand = commandFactory<FollowUserPayload>(async ({ get, path, payload: { username, following } }) => {
	const token = get(path('user', 'token'));
	const response = await fetch(`${baseUrl}/profiles/${username}/follow`, {
		method: following ? 'delete' : 'post',
		headers: getHeaders(token)
	});
	const json = await response.json();

	return [replace(path('profile'), json.profile)];
});

const getProfileCommand = commandFactory<UsernamePayload>(async ({ get, path, payload: { username } }) => {
	const token = get(path('user', 'token'));
	const response = await fetch(`${baseUrl}/profiles/${username}`, {
		headers: getHeaders(token)
	});
	const json = await response.json();

	return [
		replace(path('profile', 'image'), json.profile.image),
		replace(path('profile', 'bio'), json.profile.bio),
		replace(path('profile', 'following'), json.profile.following),
		replace(path('profile', 'loading'), false),
		replace(path('profile', 'loaded'), true)
	];
});

export const getProfileProcess = createProcess('get-profile', [startGetProfileCommand, getProfileCommand]);
export const followUserProcess = createProcess('follow-user', [followUserCommand]);
开发者ID:dojo,项目名称:examples,代码行数:29,代码来源:profileProcesses.ts


注:本文中的@dojo/framework/stores/process.createProcess函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。