MCPcopy Create free account
hub / github.com/angular/angular / producerRecomputeValue

Function producerRecomputeValue

packages/core/primitives/signals/src/computed.ts:132–173  ·  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 node.error = null;
157 } catch (err) {
158 newValue = ERRORED;
159 node.error = err;
160 } finally {
161 consumerAfterComputation(node, prevConsumer);
162 }
163
164 if (wasEqual) {
165 // No change to `valueVersion` - old and new values are
166 // semantically equivalent.
167 node.value = oldValue;
168 return;
169 }
170
171 node.value = newValue;
172 node.version++;
173 },
174 };
175})();

Callers

nothing calls this directly

Calls 3

setActiveConsumerFunction · 0.90
consumerAfterComputationFunction · 0.90

Tested by

no test coverage detected