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


TypeScript operations.replace函數代碼示例

本文整理匯總了TypeScript中@dojo/stores/state/operations.replace函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript replace函數的具體用法?TypeScript replace怎麽用?TypeScript replace使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了replace函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: get

const fetchFeedCommand = commandFactory<FetchFeedPayload>(async ({ get, path, payload: { type, page, filter } }) => {
	const token = get(path('user', 'token'));
	const offset = page * 10;
	let url: string;

	switch (type) {
		case 'feed':
			url = `${baseUrl}/articles/feed?`;
			break;
		case 'favorites':
			url = `${baseUrl}/articles?favorited=${filter}&`;
			break;
		case 'user':
			url = `${baseUrl}/articles?author=${filter}&`;
			break;
		case 'tag':
			url = `${baseUrl}/articles?tag=${filter}&`;
			break;
		default:
			url = `${baseUrl}/articles/?`;
			break;
	}

	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)
	];
});
開發者ID:agubler,項目名稱:examples,代碼行數:33,代碼來源:feedProcesses.ts

示例2: commandFactory

const clearRegisterInputs = commandFactory(({ path }) => {
	return [
		replace(path('register', 'password'), ''),
		replace(path('register', 'email'), ''),
		replace(path('register', 'username'), '')
	];
});
開發者ID:agubler,項目名稱:examples,代碼行數:7,代碼來源:loginProcesses.ts

示例3: commandFactory

const saveTodoCommand = commandFactory(({ get, path }): PatchOperation[] => {
	const editedTodo = get(path('editedTodo'));

	return editedTodo ? [
		replace(path('todos', editedTodo.id), editedTodo),
		replace(path('editedTodo'), undefined)
	] : [];
});
開發者ID:agubler,項目名稱:examples,代碼行數:8,代碼來源:todoProcesses.ts

示例4: commandFactory

const startLoadingArticleCommand = commandFactory(({ path }) => {
	return [
		replace(path('article', 'item'), undefined),
		replace(path('article', 'comments'), []),
		replace(path('article', 'loading'), true),
		replace(path('article', 'loaded'), false)
	];
});
開發者ID:agubler,項目名稱:examples,代碼行數:8,代碼來源:articleProcesses.ts

示例5: get

const loadArticleCommand = commandFactory<SlugPayload>(async ({ get, path, payload: { slug } }) => {
	const token = get(path('user', 'token'));
	const response = await fetch(`${baseUrl}/articles/${slug}`, {
		headers: getHeaders(token)
	});
	const json = await response.json();

	return [
		replace(path('article', 'item'), json.article),
		replace(path('article', 'loading'), false),
		replace(path('article', 'loaded'), true)
	];
});
開發者ID:agubler,項目名稱:examples,代碼行數:13,代碼來源:articleProcesses.ts

示例6: get

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)
	];
});
開發者ID:agubler,項目名稱:examples,代碼行數:15,代碼來源:profileProcesses.ts


注:本文中的@dojo/stores/state/operations.replace函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。