watchWithFilter
可以传入EventFilter来控制watch
用法
类似于watch
,但提供了一个将应用于回调函数的额外选项eventFilter
。
ts
import { debounceFilter, watchWithFilter } from '@mpxjs/mpxuse-core'
watchWithFilter(
source,
() => { console.log('changed!') }, // callback will be called in 500ms debounced manner
{
eventFilter: debounceFilter(500), // throttledFilter, pausabledFilter or custom filters
},
)
import { debounceFilter, watchWithFilter } from '@mpxjs/mpxuse-core'
watchWithFilter(
source,
() => { console.log('changed!') }, // callback will be called in 500ms debounced manner
{
eventFilter: debounceFilter(500), // throttledFilter, pausabledFilter or custom filters
},
)
类型声明
typescript
export interface WatchWithFilterOptions
extends WatchOptions,
ConfigurableEventFilter {}
export declare function watchWithFilter<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
sources: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchWithFilterOptions
): WatchStopHandle
export declare function watchWithFilter<
T,
Immediate extends Readonly<boolean> = false
>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchWithFilterOptions
): WatchStopHandle
export declare function watchWithFilter<
T extends object,
Immediate extends Readonly<boolean> = false
>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchWithFilterOptions
): WatchStopHandle
export interface WatchWithFilterOptions
extends WatchOptions,
ConfigurableEventFilter {}
export declare function watchWithFilter<
T extends Readonly<WatchSource<unknown>[]>,
Immediate extends Readonly<boolean> = false
>(
sources: [...T],
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchWithFilterOptions
): WatchStopHandle
export declare function watchWithFilter<
T,
Immediate extends Readonly<boolean> = false
>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchWithFilterOptions
): WatchStopHandle
export declare function watchWithFilter<
T extends object,
Immediate extends Readonly<boolean> = false
>(
source: T,
cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
options?: WatchWithFilterOptions
): WatchStopHandle