Enabled.when constructor

const Enabled.when(
  1. bool predicate(
    1. Query<Object?> query
    )
)

Decided per query, each time it matters (TanStack Query: enabled: (query) => boolean). A predicate that reads the query's state can, for instance, keep a query enabled only until it first succeeds.

"Each time it matters" is often — several calls for a single subscribe-and-fetch, and not a number to depend on. predicate must be cheap and free of side effects: it answers a question about the query, and anything else it does happens an unpredictable number of times.

Implementation

const factory Enabled.when(bool Function(Query<Object?> query) predicate) =
    EnabledWhen;