Home > widget-integration > FilterStore > watch
FilterStore.watch() method
Subscribes to changes of a specific filter state property.
Watch a single property for changes. More efficient than watching the entire state when you only care about specific properties.
Signature:
watch<K extends keyof FilterStates>(key: K, callback: (value: FilterStates[K]) => void): () => void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
key |
K |
The state property name to watch (e.g., 'latestRequestKey') |
|
callback |
(value: FilterStates[K]) => void |
Function called with the new property value when it changes |
Returns:
() => void
Unsubscribe function to stop watching this property
Example 1
Watch a specific property:
const unsubscribe = filterStore.watch('latestRequestKey', (key) => {
console.log('Latest request key changed to:', key);
});
Example 2
Extend to add custom watcher behavior:
window.boostWidgetIntegration.extend('FilterStore', (FilterStore) => {
return class CustomFilterStore extends FilterStore {
watch(keyOrCallback, callback) {
const unsubscribe = super.watch(keyOrCallback, callback);
console.log('New watcher registered');
return () => {
console.log('Watcher removed');
unsubscribe();
};
}
};
});