
We are now able to attach "side effects" to property value changes, from inside the component and outside.
13 lines
319 B
JavaScript
13 lines
319 B
JavaScript
/**
|
|
* Attach a "side effect" function that gets triggered on property value changes
|
|
* @param {Object} obj
|
|
* @param {(newValue: any) => void} callback
|
|
*/
|
|
export function attachEffect(obj, callback) {
|
|
const { proxy, prop } = Object.getPrototypeOf(obj);
|
|
|
|
proxy[prop] = {
|
|
attach: "effect",
|
|
callback,
|
|
};
|
|
}
|