Mutation Observer
A utility wrapper around MutationObserver. Watches its slotted content for attribute, child-list, subtree or character-data changes and emits nana-mutation.
Usage
html
| 1 | <nana-mutation-observer attr="class" child-list> |
| 2 | <div class="watched">…</div> |
| 3 | </nana-mutation-observer> |
| 4 | |
| 5 | <script> |
| 6 | document.querySelector('nana-mutation-observer') |
| 7 | .addEventListener('nana-mutation', (e) => console.log(e.detail.mutationList)); |
| 8 | </script> |
Import
ts
| 1 | import "@nana-tec/ui-components/mutation-observer"; |
Props
| Attribute | Type | Description |
|---|---|---|
attr | string | Attribute names to watch (space-separated) or * |
attr-old-value | boolean | Include attribute old values |
child-list | boolean | Watch additions/removals |
char-data | boolean | Watch text content |
char-data-old-value | boolean | Include character-data old values |
disabled | boolean | Stop observing |