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


TypeScript ref.newRef函數代碼示例

本文整理匯總了TypeScript中@jonggrang/ref.newRef函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript newRef函數的具體用法?TypeScript newRef怎麽用?TypeScript newRef使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了newRef函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addItem

 .chain(stateRef =>
   R.newRef<T.Fiber<void> | undefined>(void 0).map(tidRef =>
     ({ add: addItem(settings, stateRef, tidRef)
     , read: readState(stateRef, settings.empty)
     , stop: stopReaper(stateRef, settings.empty)
     , kill: killReaper(tidRef)
     })
   )
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:8,代碼來源:reaper.ts

示例2: runSubs

 function runSubs(int: Loop<E.Either<M, Q>>, subs: Q[]) {
   return newRef(int).chain(ref => {
     return T.forInPar(subs, q => {
       return readRef(ref)
         .chain(k => k.loop(E.right(q)))
         .chain(nq => writeRef(ref, nq));
     }).then(readRef(ref));
   });
 }
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:9,代碼來源:genjer.ts

示例3: withFdCache

 T.supervise(T.co(function* () {
   let fdRef: R.Ref<number> = yield R.newRef(-1);
   yield withFdCache(3000, getFd =>
     getFd(0)(path.join(__dirname, '..', 'package.json')).chain(fd =>
       R.writeRef(fdRef, (fd[0] as any).value))
   );
   let fd: number = yield R.readRef(fdRef);
   return T.attempt(T.node(null, fd, fs.readFile)).chain(mcont => {
     assert.ok(isLeft(mcont));
     return T.pure(void 0);
   });
 }))
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:12,代碼來源:fd-cache.test.ts

示例4: push

export function fix<I>(
  proc: EvQueue<I, I>
): T.Task<EvInstance<I>> {
  return R.newRef<I[]>([])
    .chain(queue => {
      return R.newRef<Loop<I> | undefined>(void 0)
        .chain(machine => {
          function push(i: I): T.Task<void> {
            return R.modifyRef(queue, ys => {
              let xs = ys.slice();
              xs.push(i);
              return xs;
            });
          }
          const run: T.Task<void> =
            R.modifyRef_(machine, x => [void 0, x]).chain(i => traverse_(loop, i));
          function loop(mc: Loop<I>): T.Task<void> {
            return R.readRef(queue)
              .chain(q => {
                if (q.length > 0) {
                  let head = q[0],
                    tail = q.slice(1);
                  return R.writeRef(queue, tail)
                    .chain(() => mc.loop(head).chain(loop));
                }
                return mc.tick()
                  .chain(st => {
                    return R.readRef(queue)
                      .chain(q2 => {
                        if (q2.length === 0) {
                          return R.writeRef(machine, st)
                            .then(R.writeRef(queue, []));
                        }
                        return loop(st);
                      });
                  });
              });
          }
          const inst: EvInstance<I> = { run, push };
          return proc(inst)
            .chain(step => {
              return R.writeRef(machine, step).then(T.pure(inst));
            });
        });
    });
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:46,代碼來源:event-queue.ts

示例5: mkAutoUpdate

 return T.toPromise(T.co(function* () {
   const ref: R.Ref<number> = yield R.newRef(0);
   const update: T.Task<number> = R.modifyRef_(ref, i => [i + 1, i + 1]);
   const next: T.Task<number> = yield mkAutoUpdate({ delay: 100, task: update });
   yield T.forIn_(range(1, 11), i => {
     return next.chain(j => {
       assert.equal(i === j && i !== 1, false);
       return T.pure(void 0);
     });
   });
   yield T.delay(300);
   const last1: number = yield R.readRef(ref);
   yield T.delay(200);
   const last2: number = yield R.readRef(ref);
   assert.equal(last1, last2);
   return T.pure(void 0);
 }));
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:17,代碼來源:auto-update.ts

示例6: handleChange

export function make<M, Q, S, I>(
  interpreter: EvQueue<E.Either<M, Q>, I>,
  app: App<M, Q, S, I>,
  el: Element
): T.Task<AppInstance<S, I>> {
  return newRef<SubscriptionState<S, I>>({ fresh: 0, cbs: {} })
    .chain(subsRef =>
      newRef<S>(app.init.model).chain(stateRef => {
        function handleChange(ac: AppChange<S, I>): T.Task<void> {
          return writeRef(stateRef, ac.model)
            .then(readRef(subsRef))
            .chain(sbs => T.forInPar(S.recordValues(sbs.cbs), cb => cb(ac)))
            .then(T.pure(void 0));
        }
        function subscribe_(cb: (_: AppChange<S, I>) => T.Task<void>): T.Task<T.Task<void>> {
          return readRef(subsRef)
            .chain(sbs => {
              let nkey = sbs.fresh.toString();
              return writeRef(subsRef, S.assign({}, sbs, {
                fresh: sbs.fresh + 1,
                sbs: S.assign({}, sbs.cbs, {
                  [nkey]: cb
                })
              })).map(v => remove(nkey));
            });
        }
        function remove(key: string): T.Task<void> {
          return modifyRef(subsRef, sbs => {
            let nbs = S.assign({}, sbs);
            delete nbs.cbs[key];
            return nbs;
          });
        }
        return fix(makeAppQueue(handleChange, interpreter, app, el))
          .map(queue =>
            ({ push: (i: I) => queue.push({ tag: AppActionType.ACTION, payload: i }),
              snapshot: readRef(stateRef),
              restore: (s: S) => queue.push({ tag: AppActionType.RESTORE, payload: s }),
              subscribe: subscribe_,
              run: queue.run
            })
          );
      })
    );
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:45,代碼來源:genjer.ts

示例7: co

  return co(function* () {
    let needsRunning: AVar<null> = yield newEmptyAVar;
    let responseVar0: AVar<A> = yield newEmptyAVar;
    let currRef: Ref<Either<AVar<A>, A>> = yield newRef(left(responseVar0));
    function loop(responseVar: AVar<A>, ma: Maybe<A>): Task<void> {
      return co(function* () {
        yield takeAVar(needsRunning);
        const a: A = yield maybe(set.task, identity, applyMaybe(modify, ma)) as Task<A>;
        yield writeRef(currRef, right(a));
        yield putAVar(responseVar, a);
        yield delay(set.delay);
        const responseVar_: AVar<A> = yield newEmptyAVar;
        yield writeRef(currRef, left(responseVar_));
        return loop(responseVar_, just(a));
      });
    }
    yield forkTask(loop(responseVar0, nothing));

    return pure(readRef(currRef).chain(mv => {
      return isLeft(mv)  ? putAVar(needsRunning, null).chain(() => readAVar(mv.value))
        /* otherwise */  : pure(mv.value);
    }));
  });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:23,代碼來源:auto-update.ts

示例8: MockStorage

export const emptyMockStorage: T.Task<MockStorage> = T.co(function* () {
  const sess: RV.Ref<Record<string, SS.Session>> = yield RV.newRef({});
  const op: RV.Ref<L.List<MockOperation>> = yield RV.newRef(L.nil);

  return T.pure(new MockStorage(sess, op));
});
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:6,代碼來源:utils.ts

示例9: action

    ? action(P.constant(getFdNothing))
    : T.bracket(initialize(duration), terminate, mfc => action(getFd(mfc)));
}

const enum Status {
  ACTIVE,
  INACTIVE
}

type MutableStatus = RV.Ref<Status>;

function status(ms: MutableStatus): T.Task<Status> {
  return RV.readRef(ms);
}

const newActiveStatus: T.Task<MutableStatus> = RV.newRef(Status.ACTIVE);

function refresh(ms: MutableStatus): T.Task<void> {
  return RV.writeRef(ms, Status.ACTIVE);
}

function inactive(ms: MutableStatus): T.Task<void> {
  return RV.writeRef(ms, Status.INACTIVE);
}

interface FdEntry {
  readonly path: string;
  readonly fd: number;
  readonly status: MutableStatus;
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:30,代碼來源:fd-cache.ts


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