watchThrottled
节流 watch.
用法
类似于watch
,但提供了一个额外的选项throttle
,该选项将应用于回调函数。
ts
import { watchThrottled } from '@mpxjs/mpxuse-core'
watchThrottled(
source,
() => { console.log('changed!') },
{ throttle: 500 },
)
import { watchThrottled } from '@mpxjs/mpxuse-core'
watchThrottled(
source,
() => { console.log('changed!') },
{ throttle: 500 },
)
它本质上是以下代码的简写:
ts
import { throttleFilter, watchWithFilter } from '@mpxjs/mpxuse-core'
watchWithFilter(
source,
() => { console.log('changed!') },
{
eventFilter: throttleFilter(500),
},
)
import { throttleFilter, watchWithFilter } from '@mpxjs/mpxuse-core'
watchWithFilter(
source,
() => { console.log('changed!') },
{
eventFilter: throttleFilter(500),
},
)
类型声明
typescript
export interface WatchThrottledOptions extends WatchOptions {
throttle?: MaybeComputedRef<number>
trailing?: boolean
leading?: boolean
}
export declare function watchThrottled<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
sources: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchThrottledOptions
): WatchStopHandle
export declare function watchThrottled<
T,
Immediate extends Readonly<boolean> = false
>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchThrottledOptions
): WatchStopHandle
export declare function watchThrottled<
T extends object,
Immediate extends Readonly<boolean> = false
>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchThrottledOptions
): WatchStopHandle
export { watchThrottled as throttledWatch }
export interface WatchThrottledOptions extends WatchOptions {
throttle?: MaybeComputedRef<number>
trailing?: boolean
leading?: boolean
}
export declare function watchThrottled<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
sources: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchThrottledOptions
): WatchStopHandle
export declare function watchThrottled<
T,
Immediate extends Readonly<boolean> = false
>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchThrottledOptions
): WatchStopHandle
export declare function watchThrottled<
T extends object,
Immediate extends Readonly<boolean> = false
>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchThrottledOptions
): WatchStopHandle
export { watchThrottled as throttledWatch }