Module: store

Simple global state management with store and reducer.

This implementation is compatible with Redux. It is intended to replace it with Redux if necessary, for example if the application grows.

Classes

Store

Methods

(static) createStore(reducer, preloadedStateopt) → {Store}

Creates a new store with the given reducer and optional preloaded state.

Parameters:
Name Type Attributes Description
reducer ReducerType

The reducer function.

preloadedState StateType <optional>

The optional initial state of the store.

Returns:

The new store.

Type
Store

Type Definitions

ActionType

An action describe an command or an event that changes the state of the application.

An action can have any properties, but it should have a type property.

Type:
  • object
Properties:
Name Type Description
type string

A string that identifies the action.

ListenerType()

A listener is a function that is called when the state of the store changes.

ReducerType(state, action) → {StateType}

A reducer is a function that changes the state of the application based on an action.

Parameters:
Name Type Description
state StateType

The current state of the application.

action ActionType

The action to handle.

Returns:

The next state of the application or the initial state if the state parameter is undefined.

Type
StateType

StateType

The application state can be any object.

Type:
  • object

UnsubscriberType()

An unsubscriber is a function that removes a listener from the store.