A store contains application state and action methods. Stores can be nested to create rich state trees.
initialState
— write-only
This property is used to set the initial state for a store instance. It defines both the 'shape' and the initial value(s) of your state properties.
If you set an object as the initial state, getters and setters for each property of that object are generated.
It is write-only, and can only be set once per instance.
import { Store } from 'megalith';
class TypicalStore extends Store {
initialState = {
version: 1,
type: 'fancy-app',
}
}
class ArrayStore extends Store {
initialStore = [1, 2, 3];
}
class NumberStore extends Store {
initialState = 0;
}
state
— read-only
(any): The store's state, not including nested child stores.
events
— read-only
(events): An events subscription manager for the store. Used to listen for action events. See events.
Dispatch an action. Actions trigger state changes and are typically created
behind the scenes by calling @action
methods.
Triggers events.
action
(Object): A plain object withtype
andpayload
properties.type
must be a string, andpayload
must be an array. See Action.
(any): The store's new state.