BaseStore
Extends:
Direct Subclass:
Indirect Subclass:
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 foundget(key)
- returns the object with the specified key. Returns undefined when not foundhas(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 |
Determines whether or not the state of this store has changed. |
|
public |
Used to reduce a stream of actions coming from the dispatcher into a |
|
public |
where(source: QueryObject): Array<object> Queries the store for resources matching the source object |
Public Constructors
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
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.
public where(source: QueryObject): Array<object> source
Queries the store for resources matching the source object
Params:
Name | Type | Attribute | Description |
source | QueryObject |