Skip to content

Instantly share code, notes, and snippets.

@rbinksy
Created February 22, 2018 16:39
Show Gist options
  • Save rbinksy/81a08b914b46418c5506118a808d85bb to your computer and use it in GitHub Desktop.
Save rbinksy/81a08b914b46418c5506118a808d85bb to your computer and use it in GitHub Desktop.
import { Map } from 'immutable';
import { createSelector } from 'reselect';
/**
* Action Types
*/
export const types = {
REQUESTLIST_FETCH_START: 'REQUESTLIST/FETCH_START',
REQUESTLIST_FETCH_SUCCESS: 'REQUESTLIST/FETCH_SUCCESS',
REQUESTLIST_FETCH_FAILURE: 'REQUESTLIST/FETCH_FAILURE'
};
/**
* Initial State for Reducer
*/
export const initialState = Map({
loading: false,
error: null,
entities: Map()
});
/**
* Reducer
*/
export default function requestListReducer(state = initialState, action) {
switch (action.type) {
case types.REQUESTLIST_FETCH_START:
return state.set('loading', true).set('error', false);
case types.REQUESTLIST_FETCH_SUCCESS:
return state.set('loading', false).set('entities', action.payload);
case types.REQUESTLIST_FETCH_FAILURE:
return state.set('loading', false).set('error', Map(action.payload));
default:
return state;
}
}
/**
* Actions
*/
export const actions = {
loadRequestList: queryParams => ({
type: types.REQUESTLIST_FETCH_START,
payload: queryParams
})
};
/**
* Selectors
*/
export const getRequestList = createSelector(
state => state.get('requestList'),
requestList => requestList
);
export const getRequestDetails = createSelector(
state => state.getIn(['requestList', 'requestDetails']),
requestList => requestList
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment