trc-client-core
Version:
The core of the TRC Client
39 lines (31 loc) • 922 B
JavaScript
import {
VEHICLES_FETCH,
VEHICLES_RECEIVE,
VEHICLES_ERROR
} from 'trc-client-core/src/constants/ActionTypes';
import {List, OrderedMap, fromJS} from 'immutable';
const initialState = fromJS({
error: null,
vehicles: null
});
export default function qanda(state = initialState, action) {
switch (action.type) {
// Fetch
case VEHICLES_FETCH:
return state.set('fetching', true);
// Error
case VEHICLES_ERROR:
return state
.set('fetching', false)
.set('error', action.payload);
// Success
case VEHICLES_RECEIVE:
return state.set('vehicles', fromJS(action.payload)
.reduce((reduction,file) => {
return reduction.set(file.get('modelName'), file)
}, OrderedMap())
);
default:
return state;
}
}