Class State<Value>

State container that represents the asynchrony of a trackedFunction

Type Parameters

  • Value

Hierarchy

  • State

Constructors

  • Type Parameters

    • Value

    Parameters

    • fn: (() => Value)
        • (): Value
        • Returns Value

    Returns State<Value>

Properties

caughtError: unknown

ember-async-data doesn't catch errors, so we can't rely on it to protect us from "leaky errors" during rendering.

See also: https://github.com/qunitjs/qunit/issues/1736

data: null | TrackedAsyncData<Value> = null
promise: Value

Accessors

  • get error(): null | Object
  • When the function passed to trackedFunction throws an error, that error will be the value returned by this property

    Returns null | Object

  • get isError(): boolean
  • Alias for isRejected

    Returns boolean

  • get isFinished(): boolean
  • Alias for isResolved || isRejected

    Returns boolean

  • get isLoading(): boolean
  • Alias for isPending

    Returns boolean

  • get isPending(): boolean
  • Initially true, and remains true until the underlying promise resolves or rejects.

    Returns boolean

  • get isRejected(): boolean
  • When true, the function passed to trackedFunction has errored

    Returns boolean

  • get isResolved(): boolean
  • When true, the function passed to trackedFunction has resolved

    Returns boolean

  • get isSettled(): boolean
  • Alias for isFinished which is in turn an alias for isResolved || isRejected

    Returns boolean

  • get state(): "PENDING" | "RESOLVED" | "REJECTED" | "UNSTARTED"
  • Returns "PENDING" | "RESOLVED" | "REJECTED" | "UNSTARTED"

  • get value(): null | Awaited<Value>
  • this.data may not exist yet.

    Additionally, prior iterations of TrackedAsyncData did not allow the accessing of data before .state === 'RESOLVED' (isResolved).

    From a correctness standpoint, this is perfectly reasonable, as it forces folks to handle the states involved with async functions.

    The original version of trackedFunction did not use TrackedAsyncData, and did not have these strictnesses upon property access, leaving folks to be as correct or as fast/prototype-y as they wished.

    For now, trackedFunction will retain that flexibility.

    Returns null | Awaited<Value>

Methods

  • Returns Promise<undefined | Value>

  • Will re-invoke the function passed to trackedFunction this will also re-set some properties on the State instance. This is the same State instance as before, as the State instance is tied to the fn passed to trackedFunction

    error or resolvedValue will remain as they were previously until this promise resolves, and then they'll be updated to the new values.

    Returns Promise<void>

Generated using TypeDoc