37 lines
678 B
JavaScript
Raw Normal View History

/*
*
* List reducer
*
*/
import { fromJS } from 'immutable';
import {
2017-01-23 20:04:12 +01:00
LOAD_RECORDS,
LOADED_RECORDS
} from './constants';
2017-01-23 20:04:12 +01:00
const initialState = fromJS({
loading: true,
currentModel: null,
2017-01-28 18:11:54 +01:00
models: {},
schema: {}
2017-01-23 20:04:12 +01:00
});
function listReducer(state = initialState, action) {
switch (action.type) {
2017-01-23 20:04:12 +01:00
case LOAD_RECORDS:
return state
.set('loading', true)
.set('currentModel', action.model);
case LOADED_RECORDS:
return state
.set('loading', false)
2017-01-28 18:11:54 +01:00
.set('schema', action.models)
2017-01-23 20:04:12 +01:00
.setIn(['models', state.get('currentModel')], action.records);
default:
return state;
}
}
export default listReducer;