• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript promise.AtomicPromise类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中spica/promise.AtomicPromise的典型用法代码示例。如果您正苦于以下问题:TypeScript AtomicPromise类的具体用法?TypeScript AtomicPromise怎么用?TypeScript AtomicPromise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了AtomicPromise类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 + '')));
     }
   }
 }
开发者ID:falsandtru,项目名称:pjax-api,代码行数:29,代码来源:script.ts


示例2: concat

 .fmap(([ss2, ap2]) =>
   AtomicPromise.all([as1, Right<Error, HTMLScriptElement[]>(ss2), ap2])
     .then(sst =>
       sst.reduce((m1, m2) =>
         m1.bind(s1 =>
           m2.fmap(s2 =>
             concat(s1, s2))))))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:7,代码来源:script.ts


示例3: wait

function wait(el: HTMLElement): AtomicPromise<Event> {
  return AtomicPromise.race([
    new AtomicPromise<Event>(resolve => void once(el, 'load', resolve)),
    new AtomicPromise<Event>(resolve => void once(el, 'abort', resolve)),
    new AtomicPromise<Event>(resolve => void once(el, 'error', resolve)),
  ]);
}
开发者ID:falsandtru,项目名称:pjax-api,代码行数:7,代码来源:content.ts


示例4: fetch

async function fetch(
  script: HTMLScriptElement,
  timeout: number,
): Promise<Either<Error, FetchData>> {
  if (!script.hasAttribute('src')) return Right<FetchData>([script, script.text]);
  if (script.type.toLowerCase() === 'module') return Right<FetchData>([script, '']);
  return AtomicPromise.race([
    window.fetch(script.src, {
      headers: new Headers({
        Accept: 'application/javascript',
      }),
      integrity: script.integrity,
    }),
    wait(timeout).then(() => AtomicPromise.reject(new Error(`${script.src}: Timeout.`))),
  ])
    .then(
      async res =>
        res.ok
          ? Right<FetchData>([script, await res.text()])
          : script.matches('[src][async]')
            ? retry(script)
                .then(
                  () => Right<FetchData>([script, '']),
                  () => Left(new Error(`${script.src}: ${res.statusText}`)))
            : Left(new Error(res.statusText)),
      (error: Error) => Left(error));
}
开发者ID:falsandtru,项目名称:pjax-api,代码行数:27,代码来源:script.ts


示例5: tuple

 .fmap(([sp, ap]) =>
   AtomicPromise.all(sp)
     .then(m => Either.sequence(m))
     .then(sm =>
       sm.fmap(ss => tuple([
         ss,
         Promise.all(ap)
           .then(m => Either.sequence(m))
       ]))));
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:script.ts


示例6: Event

 m2.fmap(([[, sp], seqD]) =>
   // Asynchronously wait for load completion of elements and scripts.
   void AtomicPromise.all([cp, sp])
     .then(process.either)
     .then(m => m
       .fmap(([events]) => (
         void window.dispatchEvent(new Event('pjax:load')),
         void config.sequence.load(seqD, events)))
       .extract(() => undefined))))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:update.ts


示例7: 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;
 })
开发者ID:falsandtru,项目名称:pjax-api,代码行数:23,代码来源:update.ts


示例8:

 .fmap(([as, ps]) =>
   [as, AtomicPromise.all(ps)] as const)))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:2,代码来源:update.ts


示例9: 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
//.........这里部分代码省略.........
开发者ID:falsandtru,项目名称:pjax-api,代码行数:101,代码来源:update.ts



注:本文中的spica/promise.AtomicPromise类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript sequence.Sequence类代码示例发布时间:2022-05-25
下一篇:
TypeScript maybe.Just函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap