mapArray and indexArray
For and Index are thin wrappers over mapArray and indexArray from @shadow-js/core.
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). Withoptions.key, it matches by key and the callback receives an item accessor.indexArray(list, map, options?)matches by position (item accessor, plain index).listis an accessor returning an array, ornull,undefinedorfalsefor empty.options.fallbackis 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.
mapruns untracked, once per row, inside the row's own root. In the keyed form its first argument is an accessor.onCleanupand 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.