(node: QuerySignalNode<V>, firstOnly: boolean)
| 109 | } |
| 110 | |
| 111 | function 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 | } |
no test coverage detected
searching dependent graphs…