Trying to understand a React-Redux codebase which uses a custom middleware in the store. The custom middleware consumes an API Client function which manages making calls to API for the actions passed to it.
In the middleware, there is a variable declaration which I cannot understand. It uses an array as the variable.
const [REQUEST, SUCCESS, FAILURE] = types;
// types: [REGISTER, REGISTER_SUCCESS, REGISTER_FAIL],
The reducer looks like this:
case LOAD:
return {
...state,
loading: true
};
case LOAD_SUCCESS:
saveAuthCookie( action.result );
return {
...state,
loading: false,
loaded: true,
user: cookie.load( userCookieName ) ? cookie.load( userCookieName ) : action.result
};
case LOAD_FAIL:
console.log(`auth LOAD_FAIL with error ${util.inspect(action.error)}`);
return {
...state,
loading: false,
loaded: false,
error: action.error
};
And the function exported by the reducer that is being called looks like this:
export function load() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
promise: (client) => client.get( '/auth/loadAuth' )
};
}