• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript process.createProcess函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: commandFactory

import { createProcess } from '@dojo/stores/process';
import { replace } from '@dojo/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:agubler,项目名称:examples,代码行数:13,代码来源:tagProcesses.ts


示例2: commandFactory

const getUserSettingsCommand = commandFactory(({ path, get }) => {
	return [replace(path('settings'), get(path('user')))];
});

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:agubler,项目名称:examples,代码行数:30,代码来源:settingsProcesses.ts


示例3: fetch

	const response = await fetch(`${url}limit=10&offset=${offset}`, { headers: getHeaders(token) });
	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:agubler,项目名称:examples,代码行数:30,代码来源:feedProcesses.ts


示例4: 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:agubler,项目名称:examples,代码行数:30,代码来源:todoProcesses.ts


示例5: 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),
		replace(path('routing', 'outlet'), 'article'),
		replace(path('routing', 'params'), { slug: json.article.slug })
	];
});

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:agubler,项目名称:examples,代码行数:30,代码来源:editorProcesses.ts


示例6: 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('routing', 'outlet'), 'home'), replace(path('user'), {})];
});

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:agubler,项目名称:examples,代码行数:30,代码来源:loginProcesses.ts


示例7: replace

import { createProcess } from '@dojo/stores/process';
import { replace } from '@dojo/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:agubler,项目名称:examples,代码行数:19,代码来源:routeProcesses.ts


示例8: 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:agubler,项目名称:examples,代码行数:29,代码来源:profileProcesses.ts


示例9: 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 [replace(path('routing', 'outlet'), 'home')];
});

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:agubler,项目名称:examples,代码行数:30,代码来源:articleProcesses.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript operations.remove函数代码示例发布时间:2022-05-28
下一篇:
TypeScript WeakMap.set函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap