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

TypeScript throttle.throttle函数代码示例

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

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



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

示例1: useEffect

  useEffect(() => {
    const handleScroll = throttle(() => setScroll(getPosition()), 250);

    window.addEventListener("scroll", handleScroll);

    return () => window.removeEventListener("scroll", handleScroll);
  }, []);
开发者ID:krzysztofwolski,项目名称:saleor,代码行数:7,代码来源:useScroll.ts


示例2: ComposeCtrl

export default function ComposeCtrl(userId: string): IComposeCtrl {

  const id = stream<string>(userId)
  const errors = stream<SendErrorResponse>()
  const autocompleteResults = stream<string[]>([])

  function send(form: HTMLFormElement) {
    const recipient = (form[0] as HTMLInputElement).value
    const subject = (form[1] as HTMLInputElement).value
    const body = (form[2] as HTMLTextAreaElement).value
    xhr.newThread(recipient, subject, body)
    .then((data: ComposeResponse) => {
      if (data.ok) {
        router.set('/inbox/' + data.id)
      }
      else {
        redraw()
      }
    })
    .catch(handleSendError)
  }

  window.addEventListener('native.keyboardhide', helper.onKeyboardHide)
  window.addEventListener('native.keyboardshow', helper.onKeyboardShow)

  function handleSendError (error: FetchError) {
    error.response.json()
    .then((errorResponse: SendErrorResponse) => {
      if (errorResponse && (errorResponse.username || errorResponse.subject || errorResponse.text)) {
        errors(errorResponse)
        redraw()
      }
      else
        throw error
    })
    .catch(handleXhrError)
  }

  return {
    id,
    errors,
    send,
    onInput: throttle((e: Event) => {
      const term = (e.target as HTMLInputElement).value.trim()
      if (term.length >= 3) {
        xhr.autocomplete(term).then(data => {
          autocompleteResults(data)
          redraw()
        })
      }
      else {
        autocompleteResults([])
        redraw()
      }
    }, 250),
    autocompleteResults
  }
}
开发者ID:sepiropht,项目名称:lichobile,代码行数:58,代码来源:ComposeCtrl.ts


示例3: studyList

function studyList(ctrl: StudyListCtrl) {
  const studies = ctrl.state ? ctrl.state.studies : []

  return h('div#scroller-wrapper.native_scroller.study-pagerScroller', {
    onscroll: throttle(ctrl.onScroll, 30),
    oncreate: helper.ontapY(e => onTap(ctrl, e!), undefined, helper.getByClass('study-pagerItem'))
  },
    ctrl.state.paginator ?
      studies.length ?
        h('ul', {
          oncreate: ctrl.afterLoad,
        }, [...studies.map((study, index) =>
          h(Item, { study, index })
        ), ctrl.state.isLoading ? h('li.study-pagerItem', 'loading...') : []]) :
          h('div.study-pagerEmpty', 'None yet') :
    h('div.study-pagerLoader', spinner.getVdom('monochrome'))
  )
}
开发者ID:mbensley,项目名称:lichobile,代码行数:18,代码来源:studyListView.ts


示例4: throttle

import * as helper from '../helper'
import router from '../../router'
import * as sleepUtils from '../../utils/sleep'
import { handleXhrError } from '../../utils'
import { acceptChallenge, declineChallenge, cancelChallenge, getChallenge } from '../../xhr'
import { Challenge } from '../../lichess/interfaces/challenge'
import challengesApi from '../../lichess/challenges'
import { standardFen } from '../../lichess/variant'
import i18n from '../../i18n'
import * as stream from 'mithril/stream'
import layout from '../layout'
import { viewOnlyBoardContent, header as headerWidget } from '../shared/common'
import { joinPopup, awaitChallengePopup, awaitInvitePopup } from './challengeView'
import { ChallengeState } from './interfaces'

const throttledPing = throttle((): void => socket.send('ping'), 1000)

interface Attrs {
  id: string
}

const ChallengeScreen: Mithril.Component<Attrs, ChallengeState> = {
  oncreate: helper.viewFadeIn,

  onremove() {
    socket.destroy()
    sleepUtils.allowSleepAgain()
    clearTimeout(this.pingTimeoutId)
  },

  oninit(vnode) {
开发者ID:mbensley,项目名称:lichobile,代码行数:31,代码来源:index.ts


示例5: all

  all() {
    return incoming.filter(supportedAndCreated).concat(sending.filter(supportedAndCreated))
  },

  incoming() {
    return incoming.filter(supportedAndCreated)
  },

  sending() {
    return sending.filter(supportedAndCreated)
  },

  set,

  refresh() {
    return throttle(getChallenges, 1000)().then(set)
  },

  remove(id: string) {
    incoming = incoming.filter((c: Challenge) => c.id !== id)
    sending = sending.filter((c: Challenge) => c.id !== id)
  },

  isPersistent(c: Challenge) {
    return c.timeControl.type === 'correspondence' ||
      c.timeControl.type === 'unlimited'
  },

  challengeTime(c: Challenge): string {
    if (isTimeControlClock(c.timeControl)) {
      return c.timeControl.show
开发者ID:mbensley,项目名称:lichobile,代码行数:31,代码来源:challenges.ts


示例6: oninit

export default {
  oncreate: helper.viewFadeIn,

  oninit() {
    socket.createDefault()

    const threads = stream<PagedThreads>()
    const isLoading = stream<boolean>(false)

    const throttledReload = throttle((p: number) => {
      isLoading(true)
      xhr.reload(p)
      .then(data => {
        threads(data)
        isLoading(false)
        redraw()
      })
      .catch(() => {
        isLoading(false)
        redraw()
      })
    }, 1000)

    xhr.inbox()
    .then(data => {
      threads(data)
      redraw()
    })
    .catch(handleXhrError)

    this.ctrl = {
开发者ID:mbensley,项目名称:lichobile,代码行数:31,代码来源:index.ts


示例7: move

  })
  lla.preloadFX('berserk', media.berserk, () => {}, (err) => {
    console.log(err)
  })
  lla.preloadFX('clock', media.clock, () => {}, (err) => {
    console.log(err)
  })
}, false)


export default {
  move() {
    if (shouldPlay) lla.play('move')
  },
  throttledMove: throttle(() => {
    if (shouldPlay) lla.play('move')
  }, 50),
  capture() {
    if (shouldPlay) lla.play('capture')
  },
  throttledCapture: throttle(() => {
    if (shouldPlay) lla.play('capture')
  }, 50),
  explosion() {
    if (shouldPlay) lla.play('explosion')
  },
  throttledExplosion: throttle(() => {
    if (shouldPlay) lla.play('explosion')
  }, 50),
  lowtime() {
    if (shouldPlay) lla.play('lowtime')
开发者ID:sepiropht,项目名称:lichobile,代码行数:31,代码来源:sound.ts


示例8: PlayersCtrl

export default function PlayersCtrl(): IPlayersCtrl {

  const isSearchOpen = stream(false)
  const searchResults: Mithril.Stream<string[]> = stream([])
  const players: Mithril.Stream<User[]> = stream([])
  let listHeight: number

  function onKeyboardShow(e: Ionic.KeyboardEvent) {
    if (window.cordova.platformId === 'ios') {
      let ul = document.getElementById('players_search_results')
      if (ul) {
        listHeight = ul.offsetHeight
        ul.style.height = (listHeight - e.keyboardHeight) + 'px'
      }
    }
  }

  function onKeyboardHide() {
    if (window.cordova.platformId === 'ios') {
      let ul = document.getElementById('players_search_results')
      if (ul) ul.style.height = listHeight + 'px'
    }
    let input = document.getElementById('searchPlayers')
    if (input) input.blur()
  }

  function closeSearch(fromBB?: string) {
    if (fromBB !== 'backbutton' && isSearchOpen()) router.backbutton.stack.pop()
      isSearchOpen(false)
  }

  function unload() {
    window.removeEventListener('keyboardDidShow', onKeyboardShow)
    window.removeEventListener('keyboardDidHide', onKeyboardHide)
  }

  window.addEventListener('keyboardDidShow', onKeyboardShow)
  window.addEventListener('keyboardDidHide', onKeyboardHide)

  xhr.onlinePlayers()
  .then(data => {
    players(data)
    redraw()
  })
  .catch(utils.handleXhrError)

  return {
    players,
    isSearchOpen,
    searchResults,
    onInput: throttle((e: Event) => {
      const term = (e.target as HTMLInputElement).value.trim()
      if (term.length >= 3)
        xhr.autocomplete(term).then(data => {
          searchResults(data)
          redraw()
        })
    }, 250),
    closeSearch,
    goSearch() {
      router.backbutton.stack.push(closeSearch)
      isSearchOpen(true)
    },
    goToProfile(u) {
      router.set('/@/' + u)
    },
    onKeyboardShow,
    onKeyboardHide,
    unload
  }
}
开发者ID:mbensley,项目名称:lichobile,代码行数:71,代码来源:PlayersCtrl.ts


示例9: players

    xhr.onlinePlayers()
    .then(data => {
      players(data)
      redraw()
    })
    .catch(utils.handleXhrError)

    vnode.state = {
      players,
      isSearchOpen,
      searchResults,
      onInput: throttle((e: Event) => {
        const term = (e.target as HTMLInputElement).value.trim()
        if (term.length >= 3)
          xhr.autocomplete(term).then(data => {
            searchResults(data)
            redraw()
          })
      }, 250),
      closeSearch,
      goSearch() {
        router.backbutton.stack.push(closeSearch)
        isSearchOpen(true)
      },
      goToProfile(u) {
        router.set('/@/' + u)
      },
      onKeyboardShow,
      onKeyboardHide
    }
  },
开发者ID:sepiropht,项目名称:lichobile,代码行数:31,代码来源:index.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript uniq.uniq函数代码示例发布时间:2022-05-28
下一篇:
TypeScript localforage.getItem函数代码示例发布时间: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