當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript AtomicPromise.resolve方法代碼示例

本文整理匯總了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 + '')));
     }
   }
 }
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:29,代碼來源:script.ts

示例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;
 })
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:23,代碼來源:update.ts

示例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
//.........這裏部分代碼省略.........
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:101,代碼來源:update.ts

示例4:

 .extract(e => AtomicPromise.resolve(Left(e))))
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:1,代碼來源:update.ts

示例5: assert

 evaluate: (script, code) => {
   assert(cnt === 1 && ++cnt);
   assert(script.className === 'test');
   assert(script.text === code);
   return Left(AtomicPromise.resolve(Right(script)));
 },
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:6,代碼來源:script.test.ts

示例6: Left

 evaluate: script => Left(AtomicPromise.resolve(Right(script))),
開發者ID:falsandtru,項目名稱:pjax-api,代碼行數:1,代碼來源:script.test.ts


注:本文中的spica/promise.AtomicPromise.resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。