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

TypeScript task.pure函数代码示例

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

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



在下文中一共展示了pure函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: lookupIndices

 const lookupResult: T.Task<P.Either<string, LookupResult>> = T.co(function* () {
   const nonIndexResult: LookupResult  = yield settings.lookupFile(pieces);
   if (nonIndexResult.tag === LookupResultType.LRFILE) {
     return T.pure(P.right(nonIndexResult));
   }
   const eIndexResult: P.Either<string, LookupResult> = yield lookupIndices(
     settings.indices.map(ix => dropLastIfNull(pieces.concat(ix)))
   );
   if (P.isLeft(eIndexResult)) {
     return T.pure(P.left(eIndexResult.value));
   }
   const { value: indexResult } = eIndexResult;
   if (indexResult.tag === LookupResultType.LRNOTFOUND) {
     return T.pure(P.right(nonIndexResult));
   }
   if (indexResult.tag === LookupResultType.LRFILE && settings.redirectToIndex) {
     const file = indexResult.file;
     return T.pure(P.left((function () {
       const repieces = pieces.slice().reverse();
       if (repieces.length === 0) {
         return file.name;
       }
       const lastSegment = repieces[0];
       if (lastSegment == '') return file.name;
       return `${lastSegment}/${file.name}`;
     })()));
   }
   return T.pure(P.right(indexResult));
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:29,代码来源:static.ts


示例2: sendRsp

function sendRsp(
  conn: Z.Connection,
  ii: Z.InternalInfo,
  status: H.Status,
  headers: H.ResponseHeaders,
  rsp: Rsp
): T.Task<[P.Maybe<H.Status>, P.Maybe<number>]> {
  switch (rsp.tag) {
    case RspType.RSPBUFFER:
      return conn.writeHead(status, headers)
        .chain(() => conn.sendAll(rsp.buffer))
        .then(T.pure([P.just(status), P.just(Buffer.byteLength(rsp.buffer))] as [P.Maybe<H.Status>, P.Maybe<number>]));

    case RspType.RSPREADABLE:
      return conn.writeHead(status, headers)
        .chain(_ => conn.sendStream(rsp.readable))
        .map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);

    case RspType.RSPNOBODY:
      return conn.writeHead(status, headers)
        .then(T.pure([P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]));

    case RspType.RSPFILE:
      if (rsp.part != null) {
        const part = rsp.part;
        return sendRspFile2XX(conn, ii, status, addContentHeadersForFilePart(headers, part),
                              rsp.path, part.offset, part.byteCount, rsp.isHead);
      }
      return T.attempt(ii.getFinfo(rsp.path))
        .chain(efinfo => {
          if (P.isLeft(efinfo)) {
            return sendRspFile404(conn, ii, headers);
          }
          const rspFile = conditionalRequest(efinfo.value, headers, rsp.header);
          switch (rspFile.tag) {
            case  RspFileInfoType.WITHBODY:
              return sendRspFile2XX(conn, ii, rspFile.status, rspFile.header, rsp.path,
                                    rspFile.offset, rspFile.length, rsp.isHead);

            case RspFileInfoType.WITHOUTBODY:
              return sendRsp(conn, ii, rspFile.status, headers, { tag: RspType.RSPNOBODY });
          }
        });

    case RspType.RSPSTREAM:
      return conn.writeHead(status, headers)
        .chain(_ => rsp.body(buff => conn.sendAll(buff)))
        .map(_ => [P.just(status), P.nothing] as [P.Maybe<H.Status>, P.Maybe<number>]);

    /* istanbul ignore next */
    default:
      throw new TypeError('last argument to sendRsp must be Rsp');
  }
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:54,代码来源:response.ts


示例3: serveFile

 return lookupResult.chain(res => {
   if (P.isLeft(res)) {
     return T.pure({ tag: StaticResponseType.RAWREDIRECT, path: res.value } as StaticResponse);
   }
   const { value: result } = res;
   if (result.tag === LookupResultType.LRNOTFOUND) {
     return T.pure({ tag: StaticResponseType.NOTFOUND } as StaticResponse);
   }
   if (result.tag === LookupResultType.LRFILE) {
     return serveFile(settings, request, result.file);
   }
   return serveFolder(settings, pieces, request, result.folder);
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:13,代码来源:static.ts


示例4: parseRequestBody

export function parseRequestBody(ctx: HttpContext, opts?: MutterOptions): T.Task<[Params, Files]> {
  if (!requestHasBody(ctx.request)) return T.pure([{}, {}] as [Params, Files]);

  const mctype = getRequestBodyType(ctx.request);

  if (isNothing(mctype)) return T.pure([{}, {}] as [Params, Files]);

  const { value: ctype } = mctype;

  return ctype.tag === 'urlencoded' ? parseUrlEncodedBody(ctx, opts)
    : ctype.tag === 'multipart' ? parseMultipartBody(ctx, opts)
      : /* istanbul ignore next */ T.pure([{}, {}] as [Params, Files]);
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:13,代码来源:parser.ts


示例5: rspFileInfo

    .chain(efinfo => {
      if (isLeft(efinfo)) {
        assert.equal(true, false);
        return T.pure(false);
      }
      const { value: finfo } = efinfo;
      let hs = S.assign({}, rsp.header, {
        'Last-Modified': finfo.date
      });

      let rsp2 = rspFileInfo(RspFileInfoType.WITHBODY, rsp.status, hs, rsp.offset, rsp.length);
      assert.deepEqual(conditionalRequest(finfo, {}, headers), rsp2);
      return T.pure(false);
    });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:14,代码来源:file.test.ts


示例6: yield

  return T.co(function* () {
    const id: string = yield generateSessionId;

    const authId: null | string = yield (
      auth === HasAuthId.HAS_AUTH_ID ? generateSessionId
        : T.pure(null));

    const keys: string[] = yield T.sequencePar(replicateArr(20, randomString(8)));
    const values: string[] = yield T.sequencePar(replicateArr(20, randomString(16)));
    const data = fromPairs(zip(keys, values));

    const now = Date.now();

    return T.pure(createSession(id, authId, data, now - 1000, now));
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:15,代码来源:storage-test.ts


示例7: update

    function update(
      state: AppState<M, Q, S>,
      action: AppAction<M, Q, S, I>
    ): T.Task<AppState<M, Q, S>> {
      let next: Transition<M, S, I>,
        needsRender: boolean,
        nextState: AppState<M, Q, S>,
        appChange: AppChange<S, I>;
      switch (action.tag) {
        case AppActionType.INTERPRET:
          return state.interpret.loop(action.payload)
            .chain(ni => {
              return T.pure(S.assign({}, state, {
                interpret: ni
              }));
            });

        case AppActionType.ACTION:
          next = app.update(state.model, action.payload);
          needsRender = state.needsRender || state.model !== next.model;
          nextState = S.assign({}, state, {
            needsRender,
            model: next.model
          });
          appChange = { old: state.model, action: action.payload, model: nextState.model };
          return onChange(appChange).then(T.forInPar(next.effects, pushEffect)).map(() => nextState);

        case AppActionType.RESTORE:
          needsRender = state.needsRender || state.model !== action.payload;
          nextState = S.assign({}, state, { needsRender, model: action.payload });
          return T.pure(nextState);
      }
    }
开发者ID:syaiful6,项目名称:jonggrang,代码行数:33,代码来源:genjer.ts


示例8:

 .chain(() => {
   let st: AppState<M, Q, S> = { snabbdom
                               , interpret: it2
                               , needsRender: false
                               , model: app.init.model };
   return T.pure({ update, commit, init: st});
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:7,代码来源:genjer.ts


示例9: it

  it('storage.destroyAllOfAuthId should only delete relevant Auth Id', function* () {
    const master: Session = yield generateSession(HasAuthId.HAS_AUTH_ID);
    const authId = master.authId as string;

    const preslaves: Session[] = yield (replicateA(20, generateSession(HasAuthId.HAS_AUTH_ID))
      .concat(replicateA(20, generateSession(HasAuthId.NO_AUTH_ID)))
    );
    const slaves = preslaves.map(x => createSession(x.id, authId, x.data, x.createdAt, x.accessedAt));

    const others: Session[] = yield (replicateA(20, generateSession(HasAuthId.HAS_AUTH_ID))
      .concat(replicateA(20, generateSession(HasAuthId.NO_AUTH_ID)))
    );
    const allS = [master].concat(slaves, others);

    // insert session
    yield T.forInPar_([master].concat(preslaves, others), x => run(storage.insert(x)));
    yield T.forInPar_(slaves, x => run(storage.replace(x)));

    const xs: (Session | null)[] = yield T.forInPar(allS, x => run(storage.get(x.id)));
    assert.deepEqual(xs, allS);
    yield run(storage.destroyAllOfAuthId(authId));
    const ys: (Session | null)[] = yield T.forInPar(allS, x => run(storage.get(x.id)));
    const xxs = new Array(slaves.length + 1).fill(null);
    assert.deepEqual(ys, xxs.concat(others as any));
    return T.pure(true);
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:26,代码来源:storage-test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript task.raise函数代码示例发布时间:2022-05-28
下一篇:
TypeScript task.node函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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