MCPcopy Index your code
hub / github.com/angular/angular / deepSignal

Function deepSignal

packages/forms/signals/src/util/deep_signal.ts:21–42  ·  view source on GitHub ↗
(
  source: WritableSignal<S>,
  prop: Signal<K>,
)

Source from the content-addressed store, hash-verified

19 * @template K The key type for S
20 */
21export function deepSignal<S, K extends keyof S>(
22 source: WritableSignal<S>,
23 prop: Signal<K>,
24): WritableSignal<S[K]> {
25 // Memoize the property.
26 const read = computed(() => source()[prop()]) as WritableSignal<S[K]>;
27
28 read[SIGNAL] = source[SIGNAL];
29 read.set = (value: S[K]) => {
30 if (Object.is(untracked(read), value)) {
31 return;
32 }
33 source.update((current) => valueForWrite(current, value, prop()) as S);
34 };
35
36 read.update = (fn: (current: S[K]) => S[K]) => {
37 read.set(fn(untracked(read)));
38 };
39 read.asReadonly = () => read;
40
41 return read;
42}
43
44/**
45 * Gets an updated root value to use when setting a value on a deepSignal with the given path.

Callers 2

constructorMethod · 0.90

Calls 8

computedFunction · 0.90
untrackedFunction · 0.90
sourceFunction · 0.85
propFunction · 0.85
valueForWriteFunction · 0.85
updateMethod · 0.65
setMethod · 0.65
fnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…