Class DataQuery

Represents an incremental data query state such as that of infinite scrollers or auto-complete dropdowns.

The class can fetch data using any arbitrary fetch function, depending on any arbitrary fetch query. The pending state of the fetch, the last successful fetch query and result, as well as the data total statistics are available.

Type parameters

Type parameter Description
QueryType

The type of the data fetch query, for instance, search strings or filter crieteria.

ItemType

The type of each item to be returned from the fetch.

constructor

devOptions

devOptions: StateDevOptions

Development-time settings

options

options: DataQueryOptions<QueryType, ItemType>

Data Query-specific options

activeQuery

  • get activeQuery(): undefined | QueryType
  • Returns the last successful query whose current results are based on. For the query used in the most recent fetch attempt, including failed fetches, use attemptedQuery.

    Returns undefined | QueryType

attemptedQuery

  • get attemptedQuery(): undefined | QueryType
  • Returns the query of the last attempted fetch. If the fetch is pending, this would be the pending query. If the fetch is complete and successful, this is the same as activeQuery.

    Returns undefined | QueryType

hasMoreItems

  • get hasMoreItems(): null | false | true
  • Returns true if there are more items to fetch, which means one of the following:

    • The most recent fetch returned isDone.
    • The current number of items is the same as or exceeds the the most recent total returned from a fetch.

    If no successful fetch has ever happened with the last attempted query, then this returns null.

    see

    FetchResultWithStats

    Returns null | false | true

isError

  • get isError(): boolean
  • Returns true if the last completed fetch encountered an error.

    Returns boolean

isFetching

  • get isFetching(): boolean
  • Returns true if data fetch is currently happening.

    Returns boolean

items

  • get items(): ItemType[]
  • Gets the items of the most recent successful fetch. This is an empty array if no successful fetch has ever happened. Note that if the most recent failed fetch is of a different query, this still holds data from the successful fetch that may be from a different query.

    Returns ItemType[]

name

  • get name(): null | string
  • Returns the UI state's debug name.

    Returns null | string

totalItems

  • get totalItems(): null | number
  • Returns the number of total items, once this is known. If the fetch function returns either isDone or total (see FetchResultWithStats), the number will be respectively be the number of items so far, or the total number.

    In case the number is not known, this returns null.

    Returns null | number

cancel

  • cancel(): void
  • Cancel any on-going data fetch. This will cause the fetch to fail. If the current fetch is a new query, the items will not clear.

    Returns void

clear

  • clear(): void
  • Cancels any pending fetch, and restores the data query into the initial state. This forgets all of the previous results and queries.

    Returns void

fetch

  • fetch(query: QueryType, fetchOptions?: undefined | object): Promise<void>
  • Starts fetchin data. The supplied query will be the attempted query and the fetch will start from offset zero always.

    Parameters

    • query: QueryType

      The query to fetch with.

    • Optional fetchOptions: undefined | object

      If force is given, any pending fetch will be canceled and a new one started even if the given query is identical to that of the pending fetch.

    Returns Promise<void>

fetchMore

  • fetchMore(): Promise<void>
  • Fetches more items using the current query. The fetch function configured in DataQueryOptions will receive an offset that is the number of items currently.

    The method can also be used for retrying a failed fetch of a new query. In this case, the offset will be zero (rather than the count of the results from a different query).

    This method is no-op if there has never been an attempted query.

    Returns Promise<void>

Generated using TypeDoc