Skip to content

watchWithFilter

Category
Export Size
233 B
Last Changed
last month

watch with additional EventFilter control.

Usage

Similar to watch, but offering an extra option eventFilter which will be applied to the callback function.

ts
import { 
debounceFilter
,
watchWithFilter
} from '@vueuse/core'
watchWithFilter
(
source, () => {
console
.
log
('changed!') }, // callback will be called in 500ms debounced manner
{
eventFilter
:
debounceFilter
(500), // throttledFilter, pausableFilter or custom filters
}, )

Type Declarations

ts
export interface 
WatchWithFilterOptions
<
Immediate
>
extends WatchOptions<
Immediate
>, ConfigurableEventFilter {}
export declare function
watchWithFilter
<
T
,
Immediate
extends
Readonly
<boolean> = false,
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
Immediate
extends true ?
T
| undefined :
T
>,
options
?:
WatchWithFilterOptions
<
Immediate
>,
):
WatchHandle
export declare function
watchWithFilter
<
T
extends
Readonly
<
MultiWatchSources
>,
Immediate
extends
Readonly
<boolean> = false,
>(
sources
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
,
Immediate
>>,
options
?:
WatchWithFilterOptions
<
Immediate
>,
):
WatchHandle
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
<
Immediate
>,
):
WatchHandle

Source

SourceDocs

Contributors

Anthony Fu
山吹色御守
Kricsleo
Arthur Darkstone
briwa
Anthony Fu
vaakian X
lvjiaxuan

Changelog

Pending for release...
f1d32 - fix(shared): align overloads order of watch functions with original version (#5288)
v14.0.0-alpha.3 on
b8102 - feat(watch): update watch return typo in watchExtractedObservable, watchDebounced, watchDeep, watchImmediate, watchOnce, watchThrottled and watchWithFilter (#4896)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

Released under the MIT License.

40% Off  yearly access to Vue School, Full course library + Vue.js Master Class.
Claim Offer