wcb/src/attach-effect.js
Ayo Ayco 73dd374a3e
feat: attach-effect (#2)
We are now able to attach "side effects" to property value changes, from inside the component and outside.
2023-12-01 08:42:10 +01:00

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,
};
}