2017-01-20 16:22:57 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* List reducer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { fromJS } from 'immutable';
|
|
|
|
import {
|
2017-01-23 20:04:12 +01:00
|
|
|
LOAD_RECORDS,
|
|
|
|
LOADED_RECORDS
|
2017-01-20 16:22:57 +01:00
|
|
|
} 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
|
|
|
});
|
2017-01-20 16:22:57 +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);
|
2017-01-20 16:22:57 +01:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default listReducer;
|