You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
595 B
JavaScript
23 lines
595 B
JavaScript
4 months ago
|
export function observeProps(props) {
|
||
|
if (!props) {
|
||
|
return;
|
||
|
}
|
||
|
Object.keys(props).forEach(key => {
|
||
|
let prop = props[key];
|
||
|
if (prop === null || !('type' in prop)) {
|
||
|
prop = { type: prop };
|
||
|
}
|
||
|
let { observer } = prop;
|
||
|
prop.observer = function () {
|
||
|
if (observer) {
|
||
|
if (typeof observer === 'string') {
|
||
|
observer = this[observer];
|
||
|
}
|
||
|
observer.apply(this, arguments);
|
||
|
}
|
||
|
this.set();
|
||
|
};
|
||
|
props[key] = prop;
|
||
|
});
|
||
|
}
|