本文整理汇总了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);
}, []);
示例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
}
}
示例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'))
)
}
示例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) {
示例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
示例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 = {
示例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')
示例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
}
}
示例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
}
},