Home Identifier Source Repository
public class | source

BaseStore

Extends:

FluxMapStore → BaseStore

A base class for resource stores.

Stores handle dispatch events from resources. When anything changes, the store's change event is omitted.

This store exposes a few methods (from it's base class). These include:

  • at(key) - returns the object with the specified key. Raises when not found
  • get(key) - returns the object with the specified key. Returns undefined when not found
  • has(key) - returns whether or not an object with the specified key exists in the store

Example:

import APIDispatcher from "../dispatcher/APIDispatcher";
import Actions       from "../utilities/Actions";
import Base          from "./Base";

let store = new BaseStore(APIDispatcher, new Actions("products"));

// listen for change events
store.addListener(() => console.log(store.get(1)));

// will cause the store to update the state and emit it's change event
APIDispatcher.dispatch({
  actionType: "MERGE_PRODUCTS",
  items: [{ id: 1, title: "My Product" }]
});

Constructor Summary

Public Constructor
public

constructor(dispatcher: APIDispatcher, actions: Actions)

Method Summary

Public Methods
public

areEqual(state1: object, state2: object): boolean

Determines whether or not the state of this store has changed.

public

reduce(state: object, action: object): object

Used to reduce a stream of actions coming from the dispatcher into a

public

Queries the store for resources matching the source object

Public Constructors

public constructor(dispatcher: APIDispatcher, actions: Actions) source

Params:

NameTypeAttributeDescription
dispatcher APIDispatcher

The dispatcher to register with

actions Actions

Public Methods

public areEqual(state1: object, state2: object): boolean source

Determines whether or not the state of this store has changed.

This method should not be called directly

Params:

NameTypeAttributeDescription
state1 object

The original state

state2 object

The new state

Return:

boolean

Whether or not the state's are identical

public reduce(state: object, action: object): object source

Used to reduce a stream of actions coming from the dispatcher into a single state object. This will handle merge and clear actions for this resource.

This method should not be called directly, but rather via a call to the dispatcher's dispatch method.

Params:

NameTypeAttributeDescription
state object

The current state

action object

The action sent by the dispatcher

Return:

object

The new state for this store

public where(source: QueryObject): Array<object> source

Queries the store for resources matching the source object

Params:

NameTypeAttributeDescription
source QueryObject

Return:

Array<object>

Resources that match the query