Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • Store

Index

Constructors

constructor

  • new Store(models: Record<string, typeof Model>): Store

Properties

Protected data

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

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

all

  • all<M>(type: string): M[]

createRecord

  • createRecord<M>(type: string, data?: ModelData): 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

find

getBy

  • getBy<M, T>(type: string, key: keyof M, value: T): undefined | M
  • Get a record from the store by the value of a model attribute.

    Type parameters

    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

getById

  • getById<M>(type: string, id: string): undefined | M
  • Get a record from the store by ID.

    Type parameters

    Parameters

    • type: string
    • id: string

    Returns undefined | M

pushObject

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

    Type parameters

    Parameters

    Returns null | M

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

  • Type parameters

    Parameters

    Returns M

pushPayload

remove

  • remove(model: Model): void

Generated using TypeDoc version 0.22.10