Skip to main content
cngx-src documentation

fromQuery

Functioninterop/query

projects/interop/query/from-query.ts

Description#

Bridge that projects a TanStack Query result onto CngxAsyncState<T>.

Reads the query's signal-bag and maps TanStack's status / fetchStatus pair onto the cngx AsyncStatus union, then hands the derived signals to buildAsyncStateView - the same single-source-of-truth kernel every other producer uses. No injection context is required (only computed()), and no boolean view is re-derived here.

Status mapping:

  • error -> error
  • success + fetching -> refreshing (background refetch, data visible)
  • success + idle/paused -> success
  • pending + fetching -> loading (first load, no data yet)
  • pending + idle/paused -> idle (disabled or paused query)
private readonly query = injectQuery(() => ({
  queryKey: ['users', this.filter()],
  queryFn: () => fetchUsers(this.filter()),
}));

readonly users = fromQuery(this.query);
// users.status(), users.data(), users.isFirstLoad() - all work
// <cngx-async-container [state]="users"> - direct binding

Signature#

fromQuery(query: CngxQueryLike)

Parameters#

@paramqueryCngxQueryLike

Returns#

CngxAsyncState