Skip to content

Latest commit

 

History

History
105 lines (68 loc) · 2.28 KB

Store.md

File metadata and controls

105 lines (68 loc) · 2.28 KB

megalith.Store

A store contains application state and action methods. Stores can be nested to create rich state trees.

Properties

Methods


Properties

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.

Example
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

Returns

(any): The store's state, not including nested child stores.


events — read-only

Returns

(events): An events subscription manager for the store. Used to listen for action events. See events.


Methods

Dispatch an action. Actions trigger state changes and are typically created behind the scenes by calling @action methods.

Triggers events.

Arguments
  1. action (Object): A plain object with type and payload properties. type must be a string, and payload must be an array. See Action.
Returns

(any): The store's new state.



Documentation