# Class: FlowQuery<TResults, TState>

A FlowQuery defines a Flo.w reactive dataset query that is executed in response to changes in application state properties.

To register a Flo.w reactive dataset query call the StateStore.registerQuery method.

The query is defined by a supplied query definition function that takes the current application state as an argument and should return a FlowQueryDefinition. Changes in application state properties referenced in the function will trigger the query to execute. For example,

(state) => {
 return {
   datasetId: 'airquality_with_params',
   limit: 10,
   params: {no2_filter: state.filterValue}
 };
}

To transform the returned data specify a result transform function, which accepts the raw query results as an array and should return a transformed value. For example,

(results) => {
 // Return the first results object from the results array
 if (results && results.length) {
   return results[0];
 } else {
   return null;
 }
}

FlowQuery exposes two reactive properties:

  • busy - indicates that the query is currently executing.
  • results - the query results.

# Type parameters

Name Default Description
TResults - Type of returned data (including transformation, if any).
TState any Type of context state. ```

# Hierarchy

  • FlowQuery

# Constructors

# constructor

+ new FlowQuery(context: FlowCoreContext<TState>, queryId: string, queryFn: FlowQueryDefinitionFn<TState>, resultTransformFn?: FlowQueryResultTransformFn<TResults>, delay?: number): FlowQuery

Constructs a FlowQuery instance.

# Parameters:

Name Type Default value Description
context FlowCoreContext<TState> - Flo.w context.
queryId string - Query ID.
queryFn FlowQueryDefinitionFn<TState> - Query definition.
resultTransformFn? FlowQueryResultTransformFn<TResults> - Result transform function.
delay number 0 Debounce delay (milliseconds)

Returns: FlowQuery

# Properties

# queryId

Readonly queryId: string

Query ID.

# Accessors

# busy

• get busy(): boolean

true if the query is currently executing and awaiting results.

Use this property to indicate busy state in the UI.

Reactive

Returns: boolean


# error

• get error(): Error

If non-null, indicates that a query error occurred

Use this property to indicate error state in the UI.

Reactive

Returns: Error


# results

• get results(): TResults

The query results.

Reactive

Returns: TResults

# Methods

# cancel

cancel(): void

Cancel the currently running query.

Returns: void


# runQueryImmediate

runQueryImmediate(): Promise<TResults>

Manually run the query. This method is provided for debugging purposes and should not generally be used. Rely on reactivity to run queries when required.

Returns: Promise<TResults>