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


TypeScript ref.modifyRef_函數代碼示例

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


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

示例1: swapWithEmpty

function reaper<W, I>(
  settings: ReaperSettings<W, I>,
  stateRef: R.Ref<State<W>>,
  tidRef: R.Ref<T.Fiber<void> | undefined>
) {
  function swapWithEmpty(s: State<W>): [State<W>, W] {
    if (s.tag === StateType.NOREAPER) {
      throw new Error('unexpected NoReaper (1)');
    }
    return [{ tag: StateType.WORKLOAD, workload: settings.empty }, s.workload ];
  }
  function check(merge: (_: W) => W, s: State<W>): [State<W>, T.Task<void>] {
    if (s.tag === StateType.NOREAPER) {
      throw new Error('unexpected NoReaper (2)');
    }
    let wl = merge(s.workload);
    return settings.isNull(wl)
      ? [{ tag: StateType.NOREAPER }, R.writeRef(tidRef, void 0)]
      : [{ tag: StateType.WORKLOAD, workload: wl }, reaper(settings, stateRef, tidRef) ];
  }
  return T.delay(settings.delay).then(
      R.modifyRef_(stateRef, swapWithEmpty))
    .chain(wl =>
      settings.action(wl))
    .chain(merge => R.modifyRef_(stateRef, s => check(merge, s)))
    .chain(identity);
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:27,代碼來源:reaper.ts

示例2: insert

  insert(sess: SS.Session) {
    return RV.modifyRef_(this.sessions, oldMap => {
      if (sess.id in oldMap) return [oldMap, T.raise(new SS.SessionAlreadyExists(oldMap[sess.id], sess))];

      return [SO.insert(sess.id, sess, oldMap), T.pure(void 0)];
    })
      .chain(identity)
      .chain(() => this.addMockOperation({ tag: 'insert', session: sess }));
  }
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:9,代碼來源:utils.ts

示例3:

function stopReaper<W>(
  s: R.Ref<State<W>>,
  empty: W
): T.Task<W> {
  return R.modifyRef_(s, mx =>
    mx.tag === StateType.NOREAPER
      ? [{ tag: StateType.NOREAPER } as State<W>, empty ]
      : [{ tag: StateType.WORKLOAD, workload: empty } as State<W>, mx.workload ]
  );
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:10,代碼來源:reaper.ts

示例4: return

 return (item: I) => {
   function cons(s: State<W>): [State<W>, T.Task<void>] {
     let wl: W;
     if (s.tag === StateType.NOREAPER) {
       wl = settings.cons(item, settings.empty);
       return [{ tag: StateType.WORKLOAD, workload: wl }, spawn(settings, stateRef, tidRef)];
     }
     wl = settings.cons(item, s.workload);
     return [{ tag: StateType.WORKLOAD, workload: wl }, T.pure(void 0)];
   }
   return R.modifyRef_(stateRef, cons)
     .chain(identity);
 };
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:13,代碼來源:reaper.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: push

 .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,代碼行數:38,代碼來源:event-queue.ts

示例7: getMockOperation

export function getMockOperation(storage: MockStorage): Promise<L.List<MockOperation>> {
  return T.toPromise(RV.modifyRef_(storage.operations, xs => [L.nil, L.reverse(xs)]));
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:3,代碼來源:utils.ts

示例8: check

 .chain(merge => R.modifyRef_(stateRef, s => check(merge, s)))
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:1,代碼來源:reaper.ts


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