本文整理汇总了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)
];
});
示例2: commandFactory
const clearRegisterInputs = commandFactory(({ path }) => {
return [
replace(path('register', 'password'), ''),
replace(path('register', 'email'), ''),
replace(path('register', 'username'), '')
];
});
示例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)
] : [];
});
示例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)
];
});
示例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)
];
});
示例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)
];
});