MCPcopy
hub / github.com/angular/angular / refreshSignalQuery

Function refreshSignalQuery

packages/core/src/render3/queries/query_reactive.ts:111–146  ·  view source on GitHub ↗
(node: QuerySignalNode<V>, firstOnly: boolean)

Source from the content-addressed store, hash-verified

109}
110
111function refreshSignalQuery<V>(node: QuerySignalNode<V>, firstOnly: boolean): V | ReadonlyArray<V> {
112 const lView = node._lView;
113 const queryIndex = node._queryIndex;
114
115 // There are 2 conditions under which we want to return "empty" results instead of the ones
116 // collected by a query:
117 //
118 // 1) a given query wasn't created yet (this is a period of time between the directive creation
119 // and execution of the query creation function) - in this case a query doesn't exist yet and we
120 // don't have any results to return.
121 //
122 // 2) we are in the process of constructing a view (the first
123 // creation pass didn't finish) and a query might have partial results, but we don't want to
124 // return those - instead we do delay results collection until all nodes had a chance of matching
125 // and we can present consistent, "atomic" (on a view level) results.
126 if (lView === undefined || queryIndex === undefined || lView[FLAGS] & LViewFlags.CreationMode) {
127 return (firstOnly ? undefined : EMPTY_ARRAY) as V;
128 }
129
130 const queryList = loadQueryInternal<V>(lView, queryIndex);
131 const results = getQueryResults<V>(lView, queryIndex);
132
133 queryList.reset(results, unwrapElementRef);
134
135 if (firstOnly) {
136 return queryList.first;
137 } else {
138 // TODO: remove access to the private _changesDetected field by abstracting / removing usage of
139 // QueryList in the signal-based queries (perf follow-up)
140 const resultChanged = (queryList as any as {_changesDetected: boolean})._changesDetected;
141 if (resultChanged || node._flatValue === undefined) {
142 return (node._flatValue = queryList.toArray());
143 }
144 return node._flatValue;
145 }
146}

Callers 1

createQuerySignalFnFunction · 0.85

Calls 4

loadQueryInternalFunction · 0.90
getQueryResultsFunction · 0.90
resetMethod · 0.65
toArrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…