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


TypeScript common.throttle函数代码示例

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


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

示例1: ctrl

export function ctrl(root: AnalyseCtrl) {

  const all = prop<any | null>(null);

  function loadGlyphs() {
    if (!all()) xhr.glyphs().then(gs => {
      all(gs);
      root.redraw();
    });
  };

  const toggleGlyph = throttle(500, (id: string) => {
    root.study!.makeChange('toggleGlyph', root.study!.withPosition({
      id
    }));
  });

  return {
    root,
    all,
    loadGlyphs,
    toggleGlyph,
    redraw: root.redraw
  };
}
开发者ID:luanlv,项目名称:lila,代码行数:25,代码来源:studyGlyph.ts

示例2: ctrl

export function ctrl(root: AnalyseCtrl) {
  const isOpen = prop(false),
  all = prop<any | null>(null);

  function loadGlyphs() {
    if (!all()) xhr.glyphs().then(function(gs) {
      all(gs);
      root.redraw();
    });
  };

  const toggleGlyph = throttle(500, false, function(id) {
    root.study!.makeChange('toggleGlyph', root.study!.withPosition({
      id
    }));
  });

  function open() {
    loadGlyphs();
    isOpen(true);
  };

  return {
    root,
    all,
    open,
    isOpen,
    toggle() {
      if (isOpen()) isOpen(false);
      else open();
    },
    toggleGlyph,
    redraw: root.redraw
  };
}
开发者ID:lexisvar,项目名称:lila,代码行数:35,代码来源:studyGlyph.ts

示例3: make

export function make(opts): EvalCache {
  const fenFetched: string[] = [];
  function hasFetched(node): boolean {
    return fenFetched.indexOf(node.fen) !== -1;
  };
  return {
    onCeval: throttle(500, function() {
      const node = opts.getNode(), ev = node.ceval;
      if (ev && !ev.cloud && hasFetched(node) && qualityCheck(ev) && opts.canPut(node)) {
        opts.send("evalPut", toPutData(opts.variant, ev));
      }
    }),
    fetch(path: Tree.Path, multiPv: number): void {
      const node = opts.getNode();
      if ((node.ceval && node.ceval.cloud) || !opts.canGet(node)) return;
      if (hasFetched(node)) return;
      fenFetched.push(node.fen);
      const obj: any = {
        fen: node.fen,
        path
      };
      if (opts.variant !== 'standard') obj.variant = opts.variant;
      if (multiPv > 1) obj.mpv = multiPv;
      opts.send("evalGet", obj);
    },
    onCloudEval(serverEval): void {
      opts.receive(toCeval(serverEval), serverEval.path);
    }
  };
};
开发者ID:luanlv,项目名称:lila,代码行数:30,代码来源:evalCache.ts

示例4: ctrl

export function ctrl(root: AnalyseCtrl): CommentForm {

  const current = prop<Current | null>(null),
  focus = prop(false),
  opening = prop(false);

  function submit(text: string): void {
    if (!current()) return;
    doSubmit(text);
  };

  const doSubmit = throttle(500, (text: string) => {
    const cur = current();
    if (cur) root.study!.makeChange('setComment', {
      ch: cur.chapterId,
      path: cur.path,
      text
    });
  });

  function start(chapterId: string, path: Tree.Path, node: Tree.Node): void {
    opening(true);
    current({
      chapterId,
      path,
      node
    });
    root.userJump(path);
  };

  return {
    root,
    current,
    focus,
    opening,
    submit,
    start,
    onSetPath(chapterId: string, path: Tree.Path, node: Tree.Node, playedMyself: boolean): void {
      setTimeout(() => {
        const cur = current();
        if (cur && (path !== cur.path || chapterId !== cur.chapterId) && (!focus() || playedMyself)) {
          cur.chapterId = chapterId;
          cur.path = path;
          cur.node = node;
          root.redraw();
        }
      }, 100);
    },
    redraw: root.redraw,
    delete(chapterId: string, path: Tree.Path, id: string) {
      root.study!.makeChange('deleteComment', {
        ch: chapterId,
        path,
        id
      });
    }
  };
}
开发者ID:luanlv,项目名称:lila,代码行数:58,代码来源:commentForm.ts

示例5: ctrl

export function ctrl(root: AnalyseCtrl, getChapter: () => StudyChapter, types) {

  const submit = throttle(500, function(name, value) {
    root.study!.makeChange('setTag', {
      chapterId: getChapter().id,
      name,
      value: value.substr(0, 140)
    });
  });

  return {
    submit(name) {
      return value => submit(name, value);
    },
    getChapter,
    types
  }
}
开发者ID:luanlv,项目名称:lila,代码行数:18,代码来源:studyTags.ts

示例6: function


//.........这里部分代码省略.........
    instanciateGamebookPlay();

    let nextPath: Tree.Path;

    if (vm.mode.sticky) {
      vm.chapterId = data.position.chapterId;
      nextPath = (
        (vm.justSetChapterId === vm.chapterId) && chapters.localPaths[vm.chapterId]
      ) || data.position.path;
    } else {
      nextPath = sameChapter ? prevPath : (chapters.localPaths[vm.chapterId] || treePath.root);
    }

    // path could be gone (because of subtree deletion), go as far as possible
    ctrl.userJump(ctrl.tree.longestValidPath(nextPath));

    vm.justSetChapterId = undefined;

    configurePractice();

    redraw();
    ctrl.startCeval();
  };

  function xhrReload() {
    vm.loading = true;
    return xhr.reload(
      practice ? 'practice/load' : 'study',
      data.id,
      vm.mode.sticky ? undefined : vm.chapterId
    ).then(onReload, li.reload);
  };

  const onSetPath = throttle(300, false, (path: Tree.Path) => {
    if (vm.mode.sticky && path !== data.position.path) makeChange("setPath", addChapterId({
      path
    }));
  });

  if (members.canContribute()) form.openIfNew();

  function currentNode() {
    return ctrl.node;
  };

  const share = shareCtrl(data, currentChapter, currentNode, redraw);

  const practice: StudyPracticeCtrl | undefined = practiceData && practiceCtrl(ctrl, data, practiceData);

  let gamebookPlay: GamebookPlayCtrl | undefined;

  function instanciateGamebookPlay() {
    if (!isGamebookPlay()) return gamebookPlay = undefined;
    if (gamebookPlay && gamebookPlay.chapterId === vm.chapterId) return;
    gamebookPlay = new GamebookPlayCtrl(ctrl, vm.chapterId, redraw);
    vm.mode.sticky = false;
  }
  instanciateGamebookPlay();

  function mutateCgConfig(config) {
    config.drawable.onChange = shapes => {
      if (vm.mode.write) {
        ctrl.tree.setShapes(shapes, ctrl.path);
        makeChange("shapes", addChapterId({
          path: ctrl.path,
          shapes
开发者ID:lexisvar,项目名称:lila,代码行数:67,代码来源:studyCtrl.ts

示例7: throttled

function throttled(sound: string): () => void {
  return throttle(100, () => window.lichess.sound[sound]())
}
开发者ID:luanlv,项目名称:lila,代码行数:3,代码来源:sound.ts

示例8: ctrl

export function ctrl(root: AnalyseCtrl): CommentForm {

  const current = prop<Current | null>(null),
  focus = prop(false),
  opening = prop(false);

  function submit(text: string): void {
    if (!current()) return;
    doSubmit(text);
  };

  const doSubmit = throttle(500, false, (text: string) => {
    const cur = current();
    if (cur) root.study!.makeChange('setComment', {
      ch: cur.chapterId,
      path: cur.path,
      text
    });
  });

  function open(chapterId: string, path: Tree.Path, node: Tree.Node): void {
    opening(true);
    current({
      chapterId,
      path,
      node
    });
    root.userJump(path);
  };

  function close() {
    current(null);
  };

  return {
    root,
    current,
    focus,
    opening,
    open,
    close,
    submit,
    onSetPath(path: Tree.Path, node: Tree.Node): void {
      const cur = current();
      if (cur && cur.path !== path && !focus()) {
        cur.path = path;
        cur.node = node;
        current(cur);
        root.redraw();
      }
    },
    redraw: root.redraw,
    toggle(chapterId: string, path: Tree.Path, node: Tree.Node) {
      if (current()) close();
      else open(chapterId, path, node);
    },
    delete(chapterId: string, path: Tree.Path, id: string) {
      root.study!.makeChange('deleteComment', {
        ch: chapterId,
        path,
        id
      });
    }
  };
}
开发者ID:lexisvar,项目名称:lila,代码行数:65,代码来源:commentForm.ts

示例9: function


//.........这里部分代码省略.........
        config.movable.color = color;
        config.premovable.enabled = true;
      } else if (vm.mode !== 'view' && color !== data.puzzle.color) {
        config.movable.color = data.puzzle.color;
        config.premovable.enabled = true;
      }
    }
    vm.cgConfig = config;
    return config;
  };

  function showGround(g) {
    g.set(makeCgOpts());
    if (!vm.node.dests) getDests();
  };

  function userMove(orig, dest, capture) {
    vm.justPlayed = orig;
    sound[capture ? 'capture' : 'move']();
    if (!promotion.start(orig, dest, sendMove)) sendMove(orig, dest);
  };

  function sendMove(orig: Key, dest: Key, prom?: cg.Role) {
    const move: any = {
      orig: orig,
      dest: dest,
      fen: vm.node.fen,
      path: vm.path
    };
    if (prom) move.promotion = prom;
    socket.sendAnaMove(move);
  };

  var getDests = throttle(800, false, function() {
    if (!vm.node.dests && treePath.contains(vm.path, vm.initialPath))
    socket.sendAnaDests({
      fen: vm.node.fen,
      path: vm.path
    });
  });

  var uciToLastMove = function(uci) {
    return uci && [uci.substr(0, 2), uci.substr(2, 2)]; // assuming standard chess
  };

  var addNode = function(node, path) {
    var newPath = tree.addNode(node, path);
    jump(newPath);
    reorderChildren(path);
    redraw();
    withGround(function(g) { g.playPremove(); });

    var progress = moveTest();
    if (progress) applyProgress(progress);
    redraw();
  };

  function reorderChildren(path: Tree.Path, recursive?: boolean) {
    var node = tree.nodeAtPath(path);
    node.children.sort(function(c1, _) {
      if (c1.puzzle === 'fail') return 1;
      if (c1.puzzle === 'retry') return 1;
      if (c1.puzzle === 'good') return -1;
      return 0;
    });
    if (recursive) node.children.forEach(function(child) {
开发者ID:lexisvar,项目名称:lila,代码行数:67,代码来源:ctrl.ts

示例10: make


//.........这里部分代码省略.........
    drop: ctrl.apiMove,
    reload,
    redirect: ctrl.setRedirecting,
    clockInc(o) {
      if (ctrl.clock) {
        ctrl.clock.addTime(o.color, o.time);
        ctrl.redraw();
      }
    },
    cclock(o) {
      if (ctrl.corresClock) {
        ctrl.data.correspondence.white = o.white;
        ctrl.data.correspondence.black = o.black;
        ctrl.corresClock.update(o.white, o.black);
        ctrl.redraw();
      }
    },
    crowd(o) {
      game.setOnGame(ctrl.data, 'white', o['white']);
      game.setOnGame(ctrl.data, 'black', o['black']);
      ctrl.redraw();
    },
    // end: function(winner) { } // use endData instead
    endData(o: ApiEnd) {
      ctrl.endWithData(o);
    },
    rematchOffer(by: Color) {
      ctrl.data.player.offeringRematch = by === ctrl.data.player.color;
      const fromOp = ctrl.data.opponent.offeringRematch = by === ctrl.data.opponent.color;
      if (fromOp) li.desktopNotification(ctrl.trans.noarg('yourOpponentWantsToPlayANewGameWithYou'));
      ctrl.redraw();
    },
    rematchTaken(nextId: string) {
      ctrl.data.game.rematch = nextId;
      if (!ctrl.data.player.spectator) ctrl.setLoading(true);
      else ctrl.redraw();
    },
    drawOffer(by) {
      ctrl.data.player.offeringDraw = by === ctrl.data.player.color;
      const fromOp = ctrl.data.opponent.offeringDraw = by === ctrl.data.opponent.color;
      if (fromOp) li.desktopNotification(ctrl.trans.noarg('yourOpponentOffersADraw'));
      ctrl.redraw();
    },
    berserk(color: Color) {
      ctrl.setBerserk(color);
    },
    gone(isGone) {
      if (!ctrl.data.opponent.ai) {
        game.setIsGone(ctrl.data, ctrl.data.opponent.color, isGone);
        ctrl.redraw();
      }
    },
    checkCount(e) {
      ctrl.data.player.checks = ctrl.data.player.color == 'white' ? e.white : e.black;
      ctrl.data.opponent.checks = ctrl.data.opponent.color == 'white' ? e.white : e.black;
      ctrl.redraw();
    },
    simulPlayerMove(gameId: string) {
      if (
        ctrl.opts.userId &&
        ctrl.data.simul &&
        ctrl.opts.userId == ctrl.data.simul.hostId &&
          gameId !== ctrl.data.game.id &&
          ctrl.moveOn.get() &&
          ctrl.chessground.state.turnColor !== ctrl.chessground.state.movable.color) {
        ctrl.setRedirecting();
        sound.move();
        li.hasToReload = true;
        location.href = '/' + gameId;
      }
    },
    simulEnd(simul: Simul) {
      $.modal($(
        '<p>Simul complete!</p><br /><br />' +
        '<a class="button" href="/simul/' + simul.id + '">Back to ' + simul.name + ' simul</a>'
      ));
    }
  };

  li.pubsub.on('ab.rep', n => send('rep', { n: n }));

  return {
    send,
    handlers,
    moreTime: throttle(300, false, () => send('moretime')),
    outoftime: throttle(500, false, () => send('flag', ctrl.data.game.player)),
    berserk: throttle(200, false, () => send('berserk', null, { ackable: true })),
    sendLoading(typ: string, data?: any) {
      ctrl.setLoading(true);
      send(typ, data);
    },
    receive(typ: string, data: any): boolean {
      if (handlers[typ]) {
        handlers[typ](data);
        return true;
      }
      return false;
    }
  };
}
开发者ID:lexisvar,项目名称:lila,代码行数:101,代码来源:socket.ts


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