DOM Observer API
spy.get()
asyncGets the names of components and the DOM elements they are observing.
- Accepts arguments as strings and arrays of strings.
You can pass component names as individual arguments, as an array, or as a string separated by commas or spaces.
Each value is seen as a new argument. - Returns an array of DOM elements that the passed component is observing, if a single argument is passed.
Returns an object where the keys are the names of the components and the values are arrays with the DOM elements that the components are observing, if multiple arguments or no arguments are passed.
Returns an array of component names that are observing the matched DOM element when a single matched DOM element.
Returns an array of arrays, where each inner array contains the names of components observing the matched DOM elements, corresponding to the number of matched DOM elements.
If the return value is missing, it will be null.
Example:
await spy.get();
// null if empty.
// {component_1: [<div>, <div>, <span>], component_2: [<span>]}
await spy.get('component_3');
// null
await spy.get('component_1');
// [<div>, <div>, <span>]
await spy.get('component_1', 'component_3');
// {component_1: [<div>, <div>, <span>], component_3: null}
await spy.get('component_1', 'component_2');
await spy.get(['component_1', 'component_2']);
await spy.get('component_1, component_2');
await spy.get('component_1 component_2');
// {component_1: [<div>, <div>, <span>], component_2: [<span>]}
await $('nav').spy.get();
// null
await $('nav ?').spy.get();
// [null, null]
await $('div').spy.get();
// ['component_1']
await $('div ?').spy.get();
// [['component_1'], ['component_1']]
await $('span').spy.get();
// ['component_1', 'component_2']
await $('span ?').spy.get();
// [['component_1', 'component_2']]
await $('nav, span ?').spy.get();
// [null, null, ['component_1', 'component_2']]