MCPcopy
hub / github.com/angular/angular / createQuerySignalFn

Function createQuerySignalFn

packages/core/src/render3/queries/query_reactive.ts:43–79  ·  view source on GitHub ↗

* A signal factory function in charge of creating a new computed signal capturing query * results. This centralized creation function is used by all types of queries (child / children, * required / optional). * * @param firstOnly indicates if all or only the first result should be returned * @p

(
  firstOnly: boolean,
  required: boolean,
  opts?: {debugName?: string},
)

Source from the content-addressed store, hash-verified

41 * @returns a read-only signal with query results
42 */
43function createQuerySignalFn<V>(
44 firstOnly: boolean,
45 required: boolean,
46 opts?: {debugName?: string},
47) {
48 let node: QuerySignalNode<V>;
49 const signalFn = createComputed(() => {
50 // A dedicated signal that increments its value every time a query changes its dirty status. By
51 // using this signal we can implement a query as computed and avoid creation of a specialized
52 // reactive node type. Please note that a query gets marked dirty under the following
53 // circumstances:
54 // - a view (where a query is active) finished its first creation pass;
55 // - a new view is inserted / deleted and it impacts query results.
56 node._dirtyCounter();
57
58 const value = refreshSignalQuery<V>(node, firstOnly);
59
60 if (required && value === undefined) {
61 throw new RuntimeError(
62 RuntimeErrorCode.REQUIRED_QUERY_NO_VALUE,
63 ngDevMode && 'Child query result is required but no value is available.',
64 );
65 }
66
67 return value;
68 });
69 node = signalFn[SIGNAL] as QuerySignalNode<V>;
70 node._dirtyCounter = signal(0);
71 node._flatValue = undefined;
72
73 if (ngDevMode) {
74 signalFn.toString = () => `[Query Signal]`;
75 node.debugName = opts?.debugName;
76 }
77
78 return signalFn;
79}
80
81export function createSingleResultOptionalQuerySignalFn<ReadT>(opts?: {
82 debugName?: string;

Calls 3

createComputedFunction · 0.90
signalFunction · 0.90
refreshSignalQueryFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…