We create actions with the new createSmartAction library.
postAuth, setToken, deleteToken - actions(and we pass directly
in it type of payload what we need,
data for postAuth, because its post request;
token for setToken action;
for deleteToken we do not need anything to pass)
Next, we create reducer with createReducer func(createSmartAction library),
which takes object with actions.toString() as a key,
and as value - payload that we passed into action
and null instead action.Regular reducer takes(state, action).
Instead getting parameters from mapStateToProps (Sylvain calls is selectors)
export const getToken = ({token}) => token;
We also need a saga for some asynchronous operations.
When we postAuth - we set token to local storage
when we clock on Log Out -> action deleteToken -> saga -> removeTokenFromLocalStorage -> localStorage.removeItem('token');
Saga helper effects(wrapping func):
call - when page load.
call and apply are well suited for functions that return Promise results
takeLatest - allows only one task to run at any moment
takeEvery - allows multiple tasks to run at any moment
put - paused until the put effect fulfilled