import { WebComponent, html } from 'web-component-base' /** * v5 `onChanges` payload: the `changes` object cleanly separates the * camelCase **property** key from the kebab-case **attribute** name. * * - `property` → camelCase prop key, matching `this.props` access (`myName`) * - `attribute` → kebab-case attribute name that changed (`my-name`) * - `previousValue` / `currentValue` * * Before v5, `property` held the kebab-case attribute name. Code that read * `changes.property` for the attribute name must now read `changes.attribute`. */ export class ChangeLogger extends WebComponent { static props = { myName: 'World', } #last = null onChanges(changes) { this.#last = changes console.log('>>> onChanges', changes) // onChanges fires after render(), so re-render to surface the payload this.render() } rename = () => { this.props.myName = this.props.myName === 'World' ? 'Ayo' : 'World' } get template() { const c = this.#last return html`
Hello ${this.props.myName}
${c ? html`No changes yet
`} ` } } customElements.define('change-logger', ChangeLogger)