diff --git a/WebComponent.mjs b/WebComponent.mjs index 96dfe85..20900cc 100644 --- a/WebComponent.mjs +++ b/WebComponent.mjs @@ -28,8 +28,7 @@ export class WebComponent extends HTMLElement { onInit() {} /** - * @template {{'previousValue': any, 'currentValue': any}} SimpleChange - * @param {Record} changes + * @param {{'property': string, 'previousValue': any, 'currentValue': any}} changes */ onChanges(changes) {} @@ -48,7 +47,7 @@ export class WebComponent extends HTMLElement { if (previousValue !== currentValue) { this[property] = currentValue; this.render(); - this.onChanges({ [property]: { previousValue, currentValue } }); + this.onChanges({ property, previousValue, currentValue }); } } diff --git a/demo/HelloWorld.mjs b/demo/HelloWorld.mjs index 565fe7a..f7585ee 100644 --- a/demo/HelloWorld.mjs +++ b/demo/HelloWorld.mjs @@ -16,10 +16,8 @@ export class HelloWorld extends WebComponent { } onChanges(changes) { - console.log("onChanges", this.querySelector("h1")); - Object.keys(changes).forEach((name) => { - console.log(name, changes[name]); - }); + const { property, previousValue, currentValue } = changes; + console.log(`${property} changed`, { previousValue, currentValue }); } get template() {