本文整理汇总了TypeScript中@dojo/framework/stores/state/operations.replace函数的典型用法代码示例。如果您正苦于以下问题:TypeScript replace函数的具体用法?TypeScript replace怎么用?TypeScript replace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: async
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:dojo,项目名称:examples,代码行数:33,代码来源:feedProcesses.ts
示例2: commandFactory
const registerCommand = commandFactory(async ({ get, path }) => {
const requestPayload = {
user: get(path('register'))
};
const response = await fetch(`${baseUrl}/users`, {
method: 'post',
body: JSON.stringify(requestPayload),
headers: getHeaders()
});
const json = await response.json();
if (!response.ok) {
return [
replace(path('register', 'failed'), true),
replace(path('register', 'loading'), false),
replace(path('errors'), json.errors),
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)
];
});
开发者ID:dojo,项目名称:examples,代码行数:31,代码来源:loginProcesses.ts
示例3: commandFactory
const publishArticleCommand = commandFactory(async ({ get, path }) => {
const token = get(path('user', 'token'));
const slug = get(path('editor', 'slug'));
const requestPayload = {
article: get(path('editor'))
};
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)
];
});
开发者ID:dojo,项目名称:examples,代码行数:25,代码来源:editorProcesses.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:dojo,项目名称:examples,代码行数:8,代码来源:articleProcesses.ts
示例5: 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:dojo,项目名称:examples,代码行数:8,代码来源:todoProcesses.ts
示例6: get
const preSortCommand = commandFactory<SortCommandPayload>(({ at, path, get, payload: { id, columnId, direction } }) => {
const page = get(path(id, 'meta', 'page'));
return [
remove(path(id, 'data', 'pages')),
replace(path(id, 'meta', 'fetchedPages'), page === 1 ? [1] : [page, page - 1]),
replace(path(id, 'meta', 'sort', 'columnId'), columnId),
replace(path(id, 'meta', 'sort', 'direction'), direction),
replace(path(id, 'meta', 'isSorting'), true)
];
});
开发者ID:dojo,项目名称:widgets,代码行数:10,代码来源:processes.ts
示例7: remove
const preFilterCommand = commandFactory<FilterCommandPayload>(({ at, path, get, payload: { id, filterOptions } }) => {
return [
remove(path(id, 'data', 'pages')),
replace(path(id, 'meta', 'fetchedPages'), [1]),
replace(path(id, 'meta', 'filter', filterOptions.columnId), filterOptions.value),
replace(path(id, 'meta', 'currentFilter'), filterOptions),
replace(path(id, 'meta', 'page'), 1),
replace(path(id, 'meta', 'isSorting'), true)
];
});
开发者ID:dojo,项目名称:widgets,代码行数:10,代码来源:processes.ts
示例8: async
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)];
}
开发者ID:dojo,项目名称:widgets,代码行数:11,代码来源:processes.ts
注:本文中的@dojo/framework/stores/state/operations.replace函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论