Adds a watcher function to a property that gets called when the property changes.
const observed = observe({
price: 43,
qty: 10,
total() {
return this.qty * this.price;
}
});
addPropertyWatcher(observed, 'price', (value, oldValue) => {
console.log(value, oldValue);
});
// watcher is called on data change
observed.price = 50; // output: 50 43
Return type of the watcher function.
Object observed with observe.
Path to the property on the data object.
Function to add to the properties' watchers.
Finds the observable attached to a property within observed data and adds or removes a watcher from its watcher list.
Object on which to register a property watcher.
Return type of the property watcher.
Object containing observed data created by observe.
Path to the property in an object.
Specifies what to do with the WatcherFunction
Removes a watcher function from a property.
const observed = observe({
price: 43,
qty: 10,
total() {
return this.qty * this.price;
}
});
const watcher = addPropertyWatcher(observed, 'price', (value, oldValue) => {
console.log(value, oldValue);
});
// watcher is called on data change
observed.price = 50; // output: 50 43
removePropertyWatcher(observed, 'price', watcher);
// no output since watcher was removed
observed.price = 90;
Return type of the watcher function.
Object observed with observe.
Path to the property on the data object.
Function to remove from the properties' watchers.
Generated using TypeDoc
Contains functionality to add watchers to observed data.