map
Reactively maps/filters items from a proxied source array or object to a new proxied array or object.
It iterates over the target proxy. For each item, it calls func.
- If
funcreturns a value, it’s added to the result proxy under the same key/index. - If
funcreturnsundefined, the item is skipped (filtered out).
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).
func
A function (value, key) => mappedValue | undefined that transforms each item.
It receives the item’s value and its key/index. Return undefined to filter the item out.
Template
Section titled “Template”IN
The type of items in the source proxy.
Template
Section titled “Template”OUT
The type of items in the resulting proxy.
Examples
Section titled “Examples”Map array values
const $numbers = A.proxy([1, 2, 3]);const $doubled = A.map($numbers, (n) => n * 2);// $doubled is proxy([2, 4, 6])
A(() => console.log($doubled)); // Logs updates$numbers.push(4); // $doubled becomes proxy([2, 4, 6, 8])Filter and map object properties
const $users = A.proxy({ 'u1': { name: 'Alice', active: true }, 'u2': { name: 'Bob', active: false }, 'u3': { name: 'Charlie', active: true }});
const $activeUserNames = A.map($users, ($user) => $user.active ? $user.name : undefined);// $activeUserNames is proxy({ u1: 'Alice', u3: 'Charlie' })A(() => console.log(Object.values($activeUserNames)));
$users.u2.active = true;// $activeUserNames becomes proxy({ u1: 'Alice', u2: 'Bob', u3: 'Charlie' })Call Signature
Section titled “Call Signature”map<
K,IN,OUT>(source,func):Map<K,OUT>
Defined in: aberdeen.ts:3265
When using a Map as source.
Type Parameters
Section titled “Type Parameters”K
IN
OUT
Parameters
Section titled “Parameters”source
Section titled “source”Map<K, IN>
(value, key) => OUT
Returns
Section titled “Returns”Map<K, OUT>
Call Signature
Section titled “Call Signature”map<
IN,OUT>(source,func):OUT[]
Defined in: aberdeen.ts:3270
When using an array as source.
Type Parameters
Section titled “Type Parameters”IN
OUT
Parameters
Section titled “Parameters”source
Section titled “source”IN[]
(value, index) => OUT
Returns
Section titled “Returns”OUT[]
Call Signature
Section titled “Call Signature”map<
IN,IN_KEY,OUT>(source,func):Record<string|symbol,OUT>
Defined in: aberdeen.ts:3275
When using an object as source.
Type Parameters
Section titled “Type Parameters”IN
IN_KEY
Section titled “IN_KEY”IN_KEY extends string | number | symbol
OUT
Parameters
Section titled “Parameters”source
Section titled “source”Record<IN_KEY, IN>
(value, index) => OUT
Returns
Section titled “Returns”Record<string | symbol, OUT>