本文整理汇总了TypeScript中apollo-cache.ApolloCache.recordOptimisticTransaction方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ApolloCache.recordOptimisticTransaction方法的具体用法?TypeScript ApolloCache.recordOptimisticTransaction怎么用?TypeScript ApolloCache.recordOptimisticTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apollo-cache.ApolloCache
的用法示例。
在下文中一共展示了ApolloCache.recordOptimisticTransaction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: markMutationInit
public markMutationInit(mutation: {
mutationId: string;
document: DocumentNode;
variables: any;
updateQueries: { [queryId: string]: QueryWithUpdater };
update: ((proxy: DataProxy, mutationResult: Object) => void) | undefined;
optimisticResponse: Object | Function | undefined;
}) {
if (mutation.optimisticResponse) {
let optimistic: Object;
if (typeof mutation.optimisticResponse === 'function') {
optimistic = mutation.optimisticResponse(mutation.variables);
} else {
optimistic = mutation.optimisticResponse;
}
const changeFn = () => {
this.markMutationResult({
mutationId: mutation.mutationId,
result: { data: optimistic },
document: mutation.document,
variables: mutation.variables,
updateQueries: mutation.updateQueries,
update: mutation.update,
});
};
this.cache.recordOptimisticTransaction(c => {
const orig = this.cache;
this.cache = c;
try {
changeFn();
} finally {
this.cache = orig;
}
}, mutation.mutationId);
}
}