Skip to content

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 func returns a value, it’s added to the result proxy under the same key/index.
  • If func returns undefined, the item is skipped (filtered out).

The returned proxy automatically updates when:

  • Items are added/removed/updated in the target proxy.
  • Any proxied data read within the func call 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.

IN

The type of items in the source proxy.

OUT

The type of items in the resulting proxy.

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' })

map<K, IN, OUT>(source, func): Map<K, OUT>

Defined in: aberdeen.ts:3265

When using a Map as source.

K

IN

OUT

Map<K, IN>

(value, key) => OUT

Map<K, OUT>

map<IN, OUT>(source, func): OUT[]

Defined in: aberdeen.ts:3270

When using an array as source.

IN

OUT

IN[]

(value, index) => OUT

OUT[]

map<IN, IN_KEY, OUT>(source, func): Record<string | symbol, OUT>

Defined in: aberdeen.ts:3275

When using an object as source.

IN

IN_KEY extends string | number | symbol

OUT

Record<IN_KEY, IN>

(value, index) => OUT

Record<string | symbol, OUT>