Dispatching a Property Change

When one of your properties has changed, store the changed property value, for example, in a variable of your Web Component JavaScript, then notify the framework of this change by dispatching a propertiesChanged custom event.

The following example shows dispatching a property change of property color:
Do dispatch a propertiesChanged custom event in the following situations:
  • as a result of a user interaction

  • in native JavaScript functions

Do not dispatch a propertiesChanged custom event in the following situations and functions, as this may cause, for example, an endless loop in JavaScript execution:
  • constructor

  • onCustomWidgetBeforeUpdate

  • onCustomWidgetAfterUpdate

  • onCustomWidgetDestroy

  • connectedCallback

  • disconnectedCallback

Note that after dispatching the propertiesChanged custom event, the changed property value is not part of the properties that are passed later to the onCustomWidgetBeforeUpdate(oChangedProperties) and onCustomWidgetAfterUpdate(oChangedProperties) functions of this Web Component.

This is simply because, as this Web Component initiated dispatching the property change in the first place, it doesn’t need to be notified of it again. However, the changed property is automatically passed to related Web Components, because they need to be notified of the property change. Related Web Components of the custom widget’s Web Component proper are the Web Component of the Styling Panel and the Web Component of the Builder Panel. The same rules, with appropriately reversed roles, apply when dispatching property changes in the Web Component of the Styling Panel and the Web Component of the Builder Panel.