Skip to content

Commit 0be4e10

Browse files
authored
feat(framework): Make _property-change publicly available (#2201)
1 parent 267ba2e commit 0be4e10

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

packages/base/src/UI5Element.js

+28-11
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,28 @@ class UI5Element extends HTMLElement {
5959
this._domRefReadyPromise._deferredResolve = deferredResolve;
6060

6161
this._monitoredChildProps = new Map();
62-
this._firePropertyChange = false;
62+
this._propertyChangeListeners = new Set();
6363
this._shouldInvalidateParent = false;
6464
}
6565

66+
addEventListener(type, listener, options) {
67+
if (type === "_property-change") {
68+
this._propertyChangeListeners.add(listener);
69+
}
70+
return super.addEventListener(type, listener, options);
71+
}
72+
73+
removeEventListener(type, listener, options) {
74+
if (type === "_property-change") {
75+
this._propertyChangeListeners.delete(listener);
76+
}
77+
return super.removeEventListener(type, listener, options);
78+
}
79+
80+
_hasPropertyChangeListeners() {
81+
return !!this._propertyChangeListeners.size;
82+
}
83+
6684
/**
6785
* Returns a unique ID for this UI5 Element
6886
*
@@ -394,17 +412,15 @@ class UI5Element extends HTMLElement {
394412
* @private
395413
*/
396414
_attachChildPropertyUpdated(child, listenFor) {
397-
const childMetadata = child.constructor.getMetadata(),
398-
slotName = this.constructor._getSlotName(child), // all slotted children have the same configuration
399-
childProperties = childMetadata.getProperties();
415+
const slotName = this.constructor._getSlotName(child); // all slotted children have the same configuration
400416

401417
let observedProps = [],
402418
notObservedProps = [];
403419

404420
if (Array.isArray(listenFor)) {
405421
observedProps = listenFor;
406422
} else {
407-
observedProps = Array.isArray(listenFor.props) ? listenFor.props : Object.keys(childProperties);
423+
observedProps = Array.isArray(listenFor.include) ? listenFor.include : [];
408424
notObservedProps = Array.isArray(listenFor.exclude) ? listenFor.exclude : [];
409425
}
410426

@@ -413,28 +429,26 @@ class UI5Element extends HTMLElement {
413429
}
414430

415431
child.addEventListener("_property-change", this._invalidateParentOnPropertyUpdate);
416-
child._firePropertyChange = true;
417432
}
418433

419434
/**
420435
* @private
421436
*/
422437
_detachChildPropertyUpdated(child) {
423438
child.removeEventListener("_property-change", this._invalidateParentOnPropertyUpdate);
424-
child._firePropertyChange = false;
425439
}
426440

427441
/**
428-
* @private
442+
* @private
429443
*/
430444
_propertyChange(name, value) {
431445
this._updateAttribute(name, value);
432446

433-
if (this._firePropertyChange) {
447+
if (this._hasPropertyChangeListeners()) {
434448
this.dispatchEvent(new CustomEvent("_property-change", {
435449
detail: { name, newValue: value },
436450
composed: false,
437-
bubbles: true,
451+
bubbles: false,
438452
}));
439453
}
440454
}
@@ -457,7 +471,10 @@ class UI5Element extends HTMLElement {
457471
}
458472
const { observedProps, notObservedProps } = propsMetadata;
459473

460-
if (observedProps.includes(prop.detail.name) && !notObservedProps.includes(prop.detail.name)) {
474+
const allPropertiesAreObserved = observedProps.length === 1 && observedProps[0] === "*";
475+
const shouldObserve = allPropertiesAreObserved || observedProps.includes(prop.detail.name);
476+
const shouldSkip = notObservedProps.includes(prop.detail.name);
477+
if (shouldObserve && !shouldSkip) {
461478
parentNode._invalidate("_parent_", this);
462479
}
463480
}

0 commit comments

Comments
 (0)