The IObservable currently being created and evaluated.
This property is globally unique because only one IObservable can be evaluated at a time.
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
Object observed with observe.
Path to the property on the data object.
Function to add to the properties' watchers.
Creates a reactive property on a specified object.
For a property to be considered reactive it needs to be proxied with a getter/setter and also have an associated Observable instance.
const obj = {};
defineReactiveProperty(obj, 'number', new Observable(99));
// Note that even though the value is proxied you can still access it as you normally access properties.
console.log(obj.number) // output: 99
obj.number = 105;
console.log(obj.number) // output: 105
Any valid javascript value.
Object on which to create the reactive property.
Key for the new property.
Observable instance that stores the value of the reactive property.
Extracts the Observable instance from a property on an object.
This function will only work if the defineReactiveProperty method was used to define that property.
Object where you have a reactive property.
Key of the property that has an observable instance.
Finds the observable attached to a property within observed data and adds or removes a watcher from its watcher list.
Object containing observed data created by observe.
Path to the property in an object.
Specifies what to do with the WatcherFunction
Traverses a string path for an object to find the property it is pointing to.
Once the property is found a callback function is called passing in the property's parent object and the property name.
const data = {
nested: {
anotherNested: {
property: 'value',
number: 66
}
}
};
navigateToPropertyPath(data, 'nested.anotherNested.property', (obj, property) => {
console.log(obj, property);
});
// output: {property: 'value', number: 66} property
Object to traverse.
Path to a property on the obj.
Callback to be called when the property is found.
Takes a data object and recursively makes all its properties reactive.
Function definitions within the data object are treated as computed property definitions.
const observed = observe({
price: 55,
quantity: 10,
total() {
return this.price * this.quantity;
}
});
console.log(observed); // output: { price: 55, quantity: 10, total: 550 }
Plain javascript object.
Object to process.
Iterate over a data object and make all its properties reactive.
Any object type: array, object, class etc.
Data object.
Observable for the data object
Removes a watcher function from a property.
const observed = observe({
price: 43,
qty: 10,
total() {
return this.qty * this.price;
}
});
const watcher = (value, oldValue) => {
console.log(value, oldValue);
}
addPropertyWatcher(observed, 'price', watcher);
// 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;
Object observed with observe.
Path to the property on the data object.
Function to remove from the properties' watchers.
Generated using TypeDoc
Module with functions that emulate vue's reactivity mechanism.