The Store class defines a local data store, and provides methods to retrieve data from the API.

Hierarchy

  • Store

Constructors

Properties

data: StoreData = {}

The local data store. A tree of resource types to IDs, such that accessing data[type][id] will return the model for that type/ID.

models: Record<string, typeof Model>

The model registry. A map of resource types to the model class that should be used to represent resources of that type.

Methods

  • Get all loaded records of a specific type.

    Type Parameters

    Parameters

    • type: string

    Returns M[]

  • Create a new record of the given type.

    Type Parameters

    Parameters

    • type: string

      The resource type

    • data: ModelData = {}

      Any data to initialize the model with

    Returns M

  • Get a record from the store by the value of a model attribute.

    Type Parameters

    • M extends Model<M>

    • T = unknown

    Parameters

    • type: string

      The resource type.

    • key: keyof M

      The name of the method on the model.

    • value: T

      The value of the model attribute.

    Returns undefined | M

  • Get a record from the store by ID.

    Type Parameters

    Parameters

    • type: string
    • id: string

    Returns undefined | M

  • Create a model to represent a resource object (or update an existing one), and push it into the store.

    Returns

    The model, or null if no model class has been registered for this resource type.

    Type Parameters

    Parameters

    Returns null | M

  • Type Parameters

    Parameters

    Returns M

Generated using TypeDoc v0.23.24