Then, for success and error, using the modified action object: store.dispatch(action)
localStorageMiddleware
Runs after promiseMiddleware. Intercepts REGISTER | LOGIN and either
a. sets token into localstorage and agent.setToken(token)
b. sets token in localstorage to '' and does agent.setToken(null)
Reducers
File: reducer.js
Imports: ./reducers/*.js
Uses combineReducers to export a reducer where each key is the reducer of the file with the same key.
General Reducer Patterns
map payload into piece of state
toggle loading states by casing on ASYNC_START and action.subtype
toggle errors by taking action.errors if it is there (see middleware)
set state keys to null if they did not come in payload (Flow type issues?)
handle redirections (will be triggered by componentWillReceiveProps somewhere)
Components
Most mapStateToProps won't be mentionned, as there are fairly simple. Take some objects, use them in render.
mapDispatchToProps will be referred to as "handlers". Some will emerge as common ones. Dispatching some specific handlers on some specific lifecylce methods will also emerge as a pattern.
Handlers:
onLoad
onUnload
onSubmit
onClick
onX
onLoad seems to be the most common one, used for any components that need ajax in data into store into props into their render method (which is basically everything on an SPA lol).
Patterns
onLoad handlers pass a Promise or multiple promises via Promise.all
sending multiple leads to magic payload[0] and payload[1] in reducer (see reducers/article.js)
pass a handler, e.g. onClickTag as a prop to a child component. child component then calls it with agent: props.onClickTag(tag, agent.Articles.byTag(tag)). (does this only ever happen with a connected index.jsx inside a folder?)
to render or not to render:
similary, if you cannot call handlers yet since props are not ready:
use componentWillReceiveProps to call handlers if necessary, e.g. in Editor.js: