This section tries to make the individual use cases clearer.
class NotifyingElement extends PolymerElement {
static get properties() {
return {
message: {
type: String,
notify: true
}}}}
class NotifyingElement extends LitElement {
static get properties() {
return {
message: {
type: String
}}}
update(props) {
super.update(props);
if (props.has('message')) {
this.dispatchEvent(new CustomEvent('message-changed', {
detail: {
value: this.message,
},
bubbles: false,
composed: true
}));
}
}
class NotifyingElement extends LitNotify(LitElement) {
static get properties() {
return {
message: {
type: String,
notify: true
}}}}
mapping a camelCase property to a kebap-case event (as PolymerElement does automaticly)
class NotifyingElement extends LitNotify(LitElement) {
static get properties() {
return {
myMessage: {
type: String,
notify: 'my-message-changed'
}}}}
Synchronizing a parent property with a childs property.
html`<element value="{{myProperty}}"></element>`
html`<element @value-changed=${(e) => this.myProperty = e.detail.value}></element>`
html`<element .value=${this.myProperty} @value-changed=${(e) => this.myProperty = e.detail.value}></element>`
html`<element .value=${this.sync('myProperty')}></element>`
* two-way binding so also updating the child when the parent property changes