MCPcopy
hub / github.com/angular/angular / producerRecomputeValue

Function producerRecomputeValue

packages/core/primitives/signals/src/computed.ts:132–172  ·  view source on GitHub ↗
(node: ComputedNode<unknown>)

Source from the content-addressed store, hash-verified

130 },
131
132 producerRecomputeValue(node: ComputedNode<unknown>): void {
133 if (node.value === COMPUTING) {
134 // Our computation somehow led to a cyclic read of itself.
135 throw new Error(
136 typeof ngDevMode !== 'undefined' && ngDevMode ? 'Detected cycle in computations.' : '',
137 );
138 }
139
140 const oldValue = node.value;
141 node.value = COMPUTING;
142
143 const prevConsumer = consumerBeforeComputation(node);
144 let newValue: unknown;
145 let wasEqual = false;
146 try {
147 newValue = node.computation();
148 // We want to mark this node as errored if calling `equal` throws; however, we don't want
149 // to track any reactive reads inside `equal`.
150 setActiveConsumer(null);
151 wasEqual =
152 oldValue !== UNSET &&
153 oldValue !== ERRORED &&
154 newValue !== ERRORED &&
155 node.equal(oldValue, newValue);
156 } catch (err) {
157 newValue = ERRORED;
158 node.error = err;
159 } finally {
160 consumerAfterComputation(node, prevConsumer);
161 }
162
163 if (wasEqual) {
164 // No change to `valueVersion` - old and new values are
165 // semantically equivalent.
166 node.value = oldValue;
167 return;
168 }
169
170 node.value = newValue;
171 node.version++;
172 },
173 };
174})();

Callers

nothing calls this directly

Calls 3

setActiveConsumerFunction · 0.90
consumerAfterComputationFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…