multiMap
Reactively maps items from a source proxy (array or object) to a target proxied object, where each source item can contribute multiple key-value pairs to the target.
It iterates over the target proxy. For each item, it calls func.
- If
funcreturns an object, all key-value pairs from that object are added to the result proxy. - If
funcreturnsundefined, the item contributes nothing.
The returned proxy automatically updates when:
- Items are added/removed/updated in the
targetproxy. - Any proxied data read within the
funccall changes (for a specific item). - If multiple input items produce the same output key, the last one processed usually “wins”, but the exact behavior on collision depends on update timing.
This is useful for “flattening” or “indexing” data, or converting an observable array to an observable object.
source
The source proxied array or object.
func
A function (value, key) => ({...pairs} | undefined) that transforms an item
into an object of key-value pairs to add, or undefined to add nothing.
Template
Section titled “Template”IN
The type of items in the source proxy.
Template
Section titled “Template”OUT
The type of the aggregated output object (should encompass all possible key-value pairs).
Example
Section titled “Example”Creating an index from an array
const $items = A.proxy([ { id: 'a', value: 10 }, { id: 'b', value: 20 },]);const $itemsById = A.multiMap($items, ($item) => ({ [$item.id]: $item.value, [$item.id+$item.id]: $item.value*10,}));// $itemsById is proxy({ a: 10, aa: 100, b: 20, bb: 200 })
A(() => console.log($itemsById));
$items.push({ id: 'c', value: 30 });// $itemsById becomes proxy({ a: 10, aa: 100, b: 20, bb: 200, c: 30, cc: 300 })Call Signature
Section titled “Call Signature”multiMap<
IN,OUT>(source,func):OUT
Defined in: aberdeen.ts:3355
When using an array as source.
Type Parameters
Section titled “Type Parameters”IN
OUT extends object
Parameters
Section titled “Parameters”source
Section titled “source”IN[]
(value, index) => OUT
Returns
Section titled “Returns”OUT
Call Signature
Section titled “Call Signature”multiMap<
K,IN,OUT>(source,func):OUT
Defined in: aberdeen.ts:3360
When using an object as source.
Type Parameters
Section titled “Type Parameters”K extends string | number | symbol
IN
OUT extends object
Parameters
Section titled “Parameters”source
Section titled “source”Record<K, IN>
(value, index) => OUT
Returns
Section titled “Returns”OUT
Call Signature
Section titled “Call Signature”multiMap<
K,IN,OUT>(source,func):OUT
Defined in: aberdeen.ts:3366
When using a Map as source.
Type Parameters
Section titled “Type Parameters”K
IN
OUT extends object
Parameters
Section titled “Parameters”source
Section titled “source”Map<K, IN>
(value, key) => OUT
Returns
Section titled “Returns”OUT