All application state is contained in a single object tree which cannot be modified directly.
Actions are used to modify the app state tree. They're objects which describe changes. They only require a type
key with other info to describe the change. Any data that will be represented by the app tree will get there via actions regardless of source (UX || Network).
{ type: "ADD_ITEM",
index: 1,
text: "hello world"
}
To describe state mutations, a single function must be written that takes the previous state of the app, the action being dispatched, and returns the next state of the app. This function has to be pure.
Accepts state
and action
where unknown actions should return the current state. If the state passed as undefined, the initial state should be returned.
Combines these principles by holding onto the current application state object and allowing actions to be dispatched which will manage changes to the state. Can be initiated with createStore
by specifying a reducer function.
getstate()
returns the current statedispatch({ type: 'SOME_ACTION' })
specify action objects to modify statesubscribe()
registers a callback which is called when an action is dispatched