Skip to main content

lens()

lens<S, T>(source, get, set): Signal<T>

Defined in: js-api/src/u2core/signals.ts:68

A writable signal over a part of source: reading it reads get(source.value) (tracked), writing it writes source.value = set(source.peek(), x). Writing the value it already reads changes nothing, so two of them wired both ways settle at once. It is a Signal: it binds wherever a signal does.

Type Parameters​

Type Parameter
S
T

Parameters​

ParameterType
sourceSignal<S>
get(s) => T
set(s, value) => S

Returns​

Signal<T>

Example​

const person = DG.U2.signal({name: 'Ann', age: 41});
const name = DG.U2.lens(person, (p) => p.name, (p, name) => ({...p, name}));
name.value = 'Bo'; // person.value is {name: 'Bo', age: 41}

See​

https://public.datagrok.ai/js/samples/ui/widgets/u2-lens