本文整理汇总了TypeScript中spica/promise.AtomicPromise.resolve方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AtomicPromise.resolve方法的具体用法?TypeScript AtomicPromise.resolve怎么用?TypeScript AtomicPromise.resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spica/promise.AtomicPromise
的用法示例。
在下文中一共展示了AtomicPromise.resolve方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: evaluate
function evaluate(): AtomicPromise<Either<Error, HTMLScriptElement>> {
if (script.matches('[type="module"][src]')) {
return AtomicPromise.resolve(import(script.src))
.catch((reason: Error) =>
reason.message.startsWith('Failed to load ') && script.matches('[src][async]')
? retry(script).catch(() => AtomicPromise.reject(reason))
: AtomicPromise.reject(reason))
.then(
() => (
void script.dispatchEvent(new Event('load')),
Right(script)),
reason => (
void script.dispatchEvent(new Event('error')),
Left(new FatalError(reason instanceof Error ? reason.message : reason + ''))));
}
else {
try {
if (new URL(standardize(window.location.href)).path !== new URL(standardize(window.location.href)).path) throw new FatalError('Expired.');
if (skip.has(new URL(standardize(window.location.href)).reference)) throw new FatalError('Expired.');
void (0, eval)(code);
script.hasAttribute('src') && void script.dispatchEvent(new Event('load'));
return AtomicPromise.resolve(Right(script));
}
catch (reason) {
script.hasAttribute('src') && void script.dispatchEvent(new Event('error'));
return AtomicPromise.resolve(Left(new FatalError(reason instanceof Error ? reason.message : reason + '')));
}
}
}
示例2: css
.fmap(async ([areas]) => {
config.update.css
? void css(documents, config.update.ignore)
: undefined;
void io.document.dispatchEvent(new Event('pjax:content'));
const seqC = await config.sequence.content(seqB, areas);
const ssm = config.update.script
? await script(documents, state.scripts, config.update, Math.max(config.fetch.timeout, 1000) * 10, process)
: await process.either<[HTMLScriptElement[], AtomicPromise<Either<Error, HTMLScriptElement[]>>]>([[], AtomicPromise.resolve(process.either([]))]);
void focus(event.type, documents.dst);
void scroll(event.type, documents.dst, {
hash: event.location.dest.fragment,
position: io.position,
});
void savePosition();
void io.document.dispatchEvent(new Event('pjax:ready'));
return [
ssm
.fmap(([ss, ap]) =>
[ss, ap.then(m => m.extract())] as const),
await config.sequence.ready(seqC),
] as const;
})
示例3: update
export function update(
{
event,
config,
state,
}: RouterEntity,
response: FetchResponse,
seq: 'fetch',
io: {
document: Document;
position: () => { top: number; left: number; };
}
): AtomicPromise<Either<Error, readonly [HTMLScriptElement[], Promise<HTMLScriptElement[]>]>> {
const { process } = state;
const documents = {
src: response.document,
dst: io.document,
};
return AtomicPromise.resolve(seq)
.then(process.either)
// fetch -> unload
.then(m => m
.bind(() =>
separate(documents, config.areas)
.extract(
() => Left(new Error(`Failed to separate the areas.`)),
() => m))
.fmap(seqA => (
void window.dispatchEvent(new Event('pjax:unload')),
config.sequence.unload(seqA, { ...response, url: response.url.reference }))))
.then(m => Either.sequence(m))
.then(process.promise)
.then(m => m
.bind(seqB =>
separate(documents, config.areas)
.fmap(([area]) =>
[seqB, area])
.extract(
() => Left(new Error(`Failed to separate the areas.`)),
process.either))
.bind(([seqB, area]) => (
void config.update.rewrite(documents.src, area),
separate(documents, config.areas)
.fmap(([, areas]) =>
[seqB, areas])
.extract(
() => Left(new Error(`Failed to separate the areas.`)),
process.either))))
.then(process.promise)
// unload -> ready
.then(m => m
.fmap(([seqB, areas]) =>
new HNil()
.extend(() => (
void blur(documents.dst),
void url(
new RouterEventLocation(response.url),
documents.src.title,
event.type,
event.source,
config.replace),
void title(documents),
void saveTitle(),
void head(documents, config.update.head, config.update.ignore),
process.either(content(documents, areas))
.fmap(([as, ps]) =>
[as, AtomicPromise.all(ps)] as const)))
.extend(async p => (await p)
.fmap(async ([areas]) => {
config.update.css
? void css(documents, config.update.ignore)
: undefined;
void io.document.dispatchEvent(new Event('pjax:content'));
const seqC = await config.sequence.content(seqB, areas);
const ssm = config.update.script
? await script(documents, state.scripts, config.update, Math.max(config.fetch.timeout, 1000) * 10, process)
: await process.either<[HTMLScriptElement[], AtomicPromise<Either<Error, HTMLScriptElement[]>>]>([[], AtomicPromise.resolve(process.either([]))]);
void focus(event.type, documents.dst);
void scroll(event.type, documents.dst, {
hash: event.location.dest.fragment,
position: io.position,
});
void savePosition();
void io.document.dispatchEvent(new Event('pjax:ready'));
return [
ssm
.fmap(([ss, ap]) =>
[ss, ap.then(m => m.extract())] as const),
await config.sequence.ready(seqC),
] as const;
})
.fmap(p =>
p.then(([m, seqD]) =>
m.fmap(sst =>
[sst, seqD] as const)))
.extract(e => AtomicPromise.resolve(Left(e))))
.reverse()
.tuple()))
.then(process.promise)
// ready -> load
//.........这里部分代码省略.........
示例4:
.extract(e => AtomicPromise.resolve(Left(e))))
示例5: assert
evaluate: (script, code) => {
assert(cnt === 1 && ++cnt);
assert(script.className === 'test');
assert(script.text === code);
return Left(AtomicPromise.resolve(Right(script)));
},
示例6: Left
evaluate: script => Left(AtomicPromise.resolve(Right(script))),