Skip to main content

Function: getListItemIterator()

getListItemIterator<HostPartT, ItemT>(host, itemLocatorBase, driverClass, startIndex?): AsyncGenerator<ItemT, void, unknown>

Defined in: packages/core/src/drivers/listHelper.ts:75

Get an iterator of list item driver. List item is an indefinite number of items under the same host

Iteration stops at the first index that does not resolve. For the homogeneous sibling set this addressing requires (see getListItemCount) that is the end of the list — but any list whose items are not a uniform run of siblings can halt it mid-list instead (a same-tag non-item shifting the reckoning, per-item wrappers making every item :nth-of-type(1); see ListEnumerationMismatchError for the full set). So on running to completion this cross-checks the number of items it reached against the number the locator actually matches, and throws ListEnumerationMismatchError when they disagree.

Truncation used to be silent, which made it strictly worse than a failure: a header <li> ahead of the items yielded an EMPTY list while getListItemCount reported 3, and getItemByLabel reported "no such item" for an item plainly present. Callers cannot detect this themselves — a short list and a genuinely short list are identical at the call site — so the check belongs here, in the primitive whose addressing creates the hazard, rather than in each of its consumers.

Costs one extra Interactor.getElementCount per completed enumeration, against the n + 1 exists() round-trips the walk already spends. A consumer that breaks out early (a label search that finds its match) never reaches the check and never pays for it — and is not making a completeness claim to check.

A walk with a non-zero startIndex is not checked; see the comment at the check for why the two reckonings cannot be reconciled across a tag-position offset.

Type Parameters​

HostPartT​

HostPartT extends ScenePart

ItemT​

ItemT extends ComponentDriver<{ }>

Parameters​

host​

ComponentDriver<HostPartT>

The component the list item is under

itemLocatorBase​

PartLocator

The locator of the list item without the index, the locator should already compound the host locator if needed

driverClass​

ComponentDriverCtor<ItemT>

The driver class of the list item

startIndex?​

number = 0

The starting index of the list item iterator, default is 0

Returns​

AsyncGenerator<ItemT, void, unknown>

Throws​

ListEnumerationMismatchError when enumeration completes having reached fewer items than itemLocatorBase matches.