본문으로 건너뛰기

함수: throttleStrategy()

function throttleStrategy(options): ThrottleStrategy;

정의 위치: packages/db/src/strategies/throttleStrategy.ts:48

시간이 지남에 따라 트랜잭션이 고르게 분산되도록 보장하는 throttle 전략을 생성합니다.

슬라이더, 진행률 표시줄 또는 스크롤 핸들러처럼 일관된 실행 타이밍이 필요한 UI 업데이트에 적합한 부드럽고 제어된 실행 패턴을 제공합니다.

매개변수​

options​

ThrottleStrategyOptions

throttle 동작을 위한 구성입니다

반환값​

ThrottleStrategy

throttle 전략 인스턴스입니다

예제​

// Throttle slider updates to every 200ms
const mutate = usePacedMutations({
onMutate: (volume) => {
settingsCollection.update('volume', draft => { draft.value = volume })
},
mutationFn: async ({ transaction }) => {
await api.updateVolume(transaction.mutations)
},
strategy: throttleStrategy({ wait: 200 })
})
// Throttle with leading and trailing execution
const mutate = usePacedMutations({
onMutate: (data) => {
collection.update(id, draft => { Object.assign(draft, data) })
},
mutationFn: async ({ transaction }) => {
await api.save(transaction.mutations)
},
strategy: throttleStrategy({
wait: 500,
leading: true,
trailing: true
})
})