@shoelace-style/shoelace
Version:
A forward-thinking library of web components.
34 lines (31 loc) • 911 B
JavaScript
import {
__spreadValues
} from "./chunk.B3BW2AY6.js";
// src/internal/watch.ts
function watch(propertyName, options) {
const resolvedOptions = __spreadValues({
waitUntilFirstUpdate: false
}, options);
return (proto, decoratedFnName) => {
const { update } = proto;
const watchedProperties = Array.isArray(propertyName) ? propertyName : [propertyName];
proto.update = function(changedProps) {
watchedProperties.forEach((property) => {
const key = property;
if (changedProps.has(key)) {
const oldValue = changedProps.get(key);
const newValue = this[key];
if (oldValue !== newValue) {
if (!resolvedOptions.waitUntilFirstUpdate || this.hasUpdated) {
this[decoratedFnName](oldValue, newValue);
}
}
}
});
update.call(this, changedProps);
};
};
}
export {
watch
};