MCPcopy Create free account
hub / github.com/ionic-team/ionic-framework / watchForOptions

Function watchForOptions

core/src/utils/watch-options.ts:1–18  ·  view source on GitHub ↗
(
  containerEl: HTMLElement,
  tagName: string,
  onChange: (el: T | undefined) => void
)

Source from the content-addressed store, hash-verified

1export const watchForOptions = <T extends HTMLElement>(
2 containerEl: HTMLElement,
3 tagName: string,
4 onChange: (el: T | undefined) => void
5) => {
6 if (typeof MutationObserver === 'undefined') {
7 return;
8 }
9
10 const mutation = new MutationObserver((mutationList) => {
11 onChange(getSelectedOption<T>(mutationList, tagName));
12 });
13 mutation.observe(containerEl, {
14 childList: true,
15 subtree: true,
16 });
17 return mutation;
18};
19
20const getSelectedOption = <T extends HTMLElement>(mutationList: MutationRecord[], tagName: string): T | undefined => {
21 let newOption: T | undefined;

Callers 2

connectedCallbackMethod · 0.90
connectedCallbackMethod · 0.90

Calls 1

getSelectedOptionFunction · 0.85

Tested by

no test coverage detected