当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript either.Left函数代码示例

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


在下文中一共展示了Left函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: compare

 m.bind(link =>
   !link.has(dst) && compare(src, dst)
     ? (
       void link.set(dst, concat(link.get(null) || [], [src])),
       void link.delete(null),
       Left(link))
     : Right(link))
开发者ID:falsandtru,项目名称:pjax-api,代码行数:7,代码来源:sync.ts

示例3: retry

 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)),
开发者ID:falsandtru,项目名称:pjax-api,代码行数:9,代码来源:script.ts

示例4: URL

 .bind(xhr => {
   const url = new URL(standardize(xhr.responseURL));
   switch (true) {
     case !xhr.responseURL:
       return Left(new Error(`Failed to get the response URL.`));
     case url.origin !== new URL(window.location.origin).origin:
       return Left(new Error(`Redirected to another origin.`));
     case !/2..|304/.test(`${xhr.status}`):
       return Left(new Error(`Failed to validate the status of response.`));
     case !xhr.responseXML:
       return method === 'GET' && xhr.status === 304 && caches.has(url.path)
         ? Right(caches.get(url.path)!.xhr)
         : Left(new Error(`Failed to get the response body.`));
     case !match(xhr.getResponseHeader('Content-Type'), 'text/html'):
       return Left(new Error(`Failed to validate the content type of response.`));
     default:
       return Right(xhr);
   }
 });
开发者ID:falsandtru,项目名称:pjax-api,代码行数:19,代码来源:xhr.ts

示例5: resolve

 err => void resolve(Left(err)),
开发者ID:falsandtru,项目名称:pjax-api,代码行数:1,代码来源:xhr.ts

示例6: 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

示例7: Left

 () => Left(new Error(`Failed to separate the areas.`)),
开发者ID:falsandtru,项目名称:pjax-api,代码行数:1,代码来源:update.ts


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