Class AsyncData<D, E>

This class represents data from a remote source that takes time to load.

It can be single-valued or an array of values. The caller is expected to know which it is

Type Parameters

  • D

    A type representing the shape of data that is being requested

  • E = {}

    A type representing the shape of errors that can be returned

Constructors

Properties

internal: Either<E, readonly D[]>
status: RemoteDataStatus = RemoteDataStatus.NotAsked

Methods

  • This returns true if the predicate returns true for every element of data.

    It is synonymous with every

    Parameters

    • predicate: ((value, index, array) => boolean)
        • (value, index, array): boolean
        • Parameters

          • value: D
          • index: number
          • array: D[]

          Returns boolean

    Returns boolean

    Throws

    an error if no response has been received

  • This returns true if the predicate returns true for any element of data.

    It is synonymous with some

    Parameters

    • predicate: ((value, index, array) => boolean)
        • (value, index, array): boolean
        • Parameters

          • value: D
          • index: number
          • array: D[]

          Returns boolean

    Returns boolean

    Throws

    an error if no response has been received

  • Returns boolean

    true if this object currently contains retrievable data, i.e. not an error and not an inflight request

  • This returns true if the predicate returns true for every element of data.

    It is synonymous with all

    Parameters

    • predicate: ((value, index, array) => boolean)
        • (value, index, array): boolean
        • Parameters

          • value: D
          • index: number
          • array: D[]

          Returns boolean

    Returns boolean

    Throws

    an error if no response has been received

  • Parameters

    • callbackfn: ((value, index?, array?) => boolean)
        • (value, index?, array?): boolean
        • Parameters

          • value: D
          • Optional index: number
          • Optional array: readonly D[]

          Returns boolean

    Returns AsyncData<D, E>

  • Parameters

    • predicate: ((value, index, obj) => boolean)
        • (value, index, obj): boolean
        • Parameters

          • value: D
          • index: number
          • obj: readonly D[]

          Returns boolean

    • Optional thisArg: unknown

    Returns undefined | D

  • Parameters

    • predicate: ((value, index, obj) => boolean)
        • (value, index, obj): boolean
        • Parameters

          • value: D
          • index: number
          • obj: readonly D[]

          Returns boolean

    • Optional thisArg: unknown

    Returns number

  • Get the data as an optional and treat it as an array

    This will return any internal data that exists. As a result, it will return data after a call to loadMore.

    Returns Optional<readonly D[]>

  • Standard response for mapping this AsyncData to a new one when no data is loaded

    Type Parameters

    • U

    Returns undefined | AsyncData<U, E>

  • Check whether data has been requested

    Returns boolean

  • Checks whether the data that was loaded is empty.

    This will throw an error if the data is not loaded yet

    Returns boolean

    Throws

  • Check whether the data errored out

    Returns boolean

  • Check whether any data has loaded (or that the request has failed)

    Returns boolean

  • Check whether data is currently loading

    Returns boolean

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((value, index, array?) => U)
        • (value, index, array?): U
        • Parameters

          • value: D
          • index: number
          • Optional array: readonly D[]

          Returns U

    Returns AsyncData<U, E>

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((value, index, array?) => U)
        • (value, index, array?): U
        • Parameters

          • value: D
          • index: number
          • Optional array: readonly D[]

          Returns U

    Returns readonly U[]

  • Treats the data as an Optional and returns the internal value or the provided value.

    Parameters

    • v: D | readonly D[]

    Returns D | readonly D[]

  • Type Parameters

    • U

    Parameters

    • callbackfn: ((previousValue, currentValue, currentIndex, array) => U)
        • (previousValue, currentValue, currentIndex, array): U
        • Parameters

          • previousValue: U
          • currentValue: D
          • currentIndex: number
          • array: readonly D[]

          Returns U

    • initialValue: U

    Returns AsyncData<U, E>

  • This returns true if the predicate returns true for any element of data.

    It is synonymous with any

    Parameters

    • predicate: ((value, index, array) => boolean)
        • (value, index, array): boolean
        • Parameters

          • value: D
          • index: number
          • array: D[]

          Returns boolean

    Returns boolean

    Throws

    an error if no response has been received

  • Sorts the elements of data, according to compareFn

    Note that this does not sort the elements in place

    Parameters

    • Optional compareFn: ((a, b) => number)

      The comparison function to be applied to the data elements. See Array.sort documentation for more detail

        • (a, b): number
        • Parameters

          Returns number

    Returns D[]

    Throws

    an error if no response has been received

  • Create an instance of this type that indicates that some data has been returned by the request.

    NB: There is nothing here that asserts that the request is complete. This factory method can be called multiple times to indicate loading data in progress.

    Type Parameters

    • LD
    • LE = {}

    Parameters

    • data: readonly LD[]

    Returns AsyncData<LD, LE>