getUnmountedInstances
getUnmountedInstances<T extends Base = Base>(name: string, root?: ParentNode): T[]
getUnmountedInstances<T extends Base = Base>(el: Element): T[]The instances of a component name that were built and are not mounted, in DOM order — or the same on one element, in mount order.
Usage
import { getUnmountedInstances } from '@studiometa/js-toolkit';
getUnmountedInstances('Video').length;What this population is
It is small and specific. It is what a reversible mount strategy leaves behind: in-view and media: unmount their instance when the condition stops holding and keep it for the crossing back, so the instance stays in the element's map with $isMounted === false.
A constructor that succeeded before a failing mounted() lands here too.
What is not here
- A declaration whose class never arrived. A lazy entry that has not loaded has no instance at all.
- A declaration withdrawn by a breakpoint. That instance is unmounted and deleted from the map, so the name later declared again builds a new one.
- A component still waiting on a mount strategy. It has never been constructed.
Neither has an instance, so neither can be in a list of them.
The two overloads
(name: string, root?: ParentNode): T[]
(el: Element): T[]- The name form searches the descendants of
root, which defaults to the document.rootis aParentNodeand the call isquerySelectorAll, so it never matchesrootitself. - The element form reads the element's instance map directly and never consults the DOM, so it answers for a detached element as readily as for a connected one. The name form cannot:
document.querySelectorAll()does not see a detached element. Pass the detached root asrootwhen a name lookup has to reach inside it.
How the narrowing works
selectorFor(name) over-matches on purpose — it lists the responsive spellings of data-component too — and the instance-map read is what removes an inactive declaration, because a breakpoint-withdrawn component is destroyed and deleted from the map.
A matching element with no instance is skipped, and that is the whole narrowing. There is no mount filter, because it never did that work.