[]previous and next page

mapArray and indexArray

For and Index are thin wrappers over mapArray and indexArray from @shadow-js/core.

For agentsUpdated

For and Index are thin wrappers over mapArray and indexArray from @shadow-js/core. Use the primitives to map data to something that is not DOM, for example view models, charts series or any structure whose per-item resources must live exactly as long as the item.

  • mapArray(list, map, options?) matches by reference (the callback receives the value and an index accessor). With options.key, it matches by key and the callback receives an item accessor.
  • indexArray(list, map, options?) matches by position (item accessor, plain index).
  • list is an accessor returning an array, or null, undefined or false for empty. options.fallback is mapped while the list is empty.
  • The result is an accessor of the mapped array. It is lazy and memoized: rows are created and disposed when the accessor is read, so a list nobody reads keeps its removed rows alive until the next read.
  • map runs untracked, once per row, inside the row's own root. In the keyed form its first argument is an accessor. onCleanup and effects created in it belong to the row and are disposed when the item leaves or the list's owner is disposed.

If map throws, the previous rows are kept, the rows created in that pass are disposed, and the error is rethrown to the reader of the accessor.