angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.36k stars 6.74k forks source link

feat(cdk/observers): Choosing CDK MutationObserver properties #29186

Open Marius-Romanus opened 5 months ago

Marius-Romanus commented 5 months ago

Feature Description

Hello, by default in the MutationObserver CDK all three types of changes are detected. It would be nice to be able to choose each of them on true or false for each use case.

https://github.com/angular/components/blob/3dc01c17f9201b2a4dcf1f1dc05c25cc2184f64c/src/cdk/observers/observe-content.ts#L131

greetings!

Use Case

Being able to choose what type of changes you want to observe.

amysorto commented 5 months ago

The MutationObserver is a native to the web, so it might not be something we could have control over in this library.

What are the types of changes you are referring to specifically? My understanding is that it will watch for any change to the DOM.

Marius-Romanus commented 5 months ago

Hi, I know it's web native, but the library hears three default options: characterData, childList and subtree. People may be interested in hearing only certain events and not all, or at least being able to choose. There is also no "attributes" property.

https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#options

observer.observe(element, {
            characterData: true,
            childList: true,
            subtree: true,
          });