Reference Source
import Store from 'flarum/common/Store'
public class | source

Store

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

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

The model registry.

Protected Members
protected

The local data store.

Method Summary

Public Methods
public

all(type: String): Model[]

Get all loaded records of a specific type.

public

createRecord(type: String, data: Object): Model

Create a new record of the given type.

public

find(type: String, id: Integer | Integer[] | Object, query: Object, options: Object): Promise

Make a request to the API to find record(s) of a specific type.

public

getBy(type: String, key: String, value: *): Model

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

public

getById(type: String, id: Integer): Model

Get a record from the store by ID.

public

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

public

pushPayload(payload: Object): Model | Model[]

Push resources contained within an API payload into the store.

public

remove(model: Model)

Remove the given model from the store.

Public Constructors

public constructor() source

Public Members

public models: Object source

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

Protected Members

protected data: Object source

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.

Public Methods

public all(type: String): Model[] source

Get all loaded records of a specific type.

Params:

NameTypeAttributeDescription
type String

Return:

Model[]

public createRecord(type: String, data: Object): Model source

Create a new record of the given type.

Params:

NameTypeAttributeDescription
type String

The resource type

data Object
  • optional

Any data to initialize the model with

Return:

Model

public find(type: String, id: Integer | Integer[] | Object, query: Object, options: Object): Promise source

Make a request to the API to find record(s) of a specific type.

Params:

NameTypeAttributeDescription
type String

The resource type.

id Integer | Integer[] | Object
  • optional

The ID(s) of the model(s) to retrieve. Alternatively, if an object is passed, it will be handled as the query parameter.

query Object
  • optional
options Object
  • optional

Return:

Promise

public getBy(type: String, key: String, value: *): Model source

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

Params:

NameTypeAttributeDescription
type String

The resource type.

key String

The name of the method on the model.

value *

The value of the model attribute.

Return:

Model

public getById(type: String, id: Integer): Model source

Get a record from the store by ID.

Params:

NameTypeAttributeDescription
type String

The resource type.

id Integer

The resource ID.

Return:

Model

public pushObject(data: Object): Model | null source

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

Params:

NameTypeAttributeDescription
data Object

The resource object

Return:

Model | null

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

public pushPayload(payload: Object): Model | Model[] source

Push resources contained within an API payload into the store.

Params:

NameTypeAttributeDescription
payload Object

Return:

Model | Model[]

The model(s) representing the resource(s) contained within the 'data' key of the payload.

public remove(model: Model) source

Remove the given model from the store.

Params:

NameTypeAttributeDescription
model Model