60 lines
1.2 KiB
JavaScript
Raw Normal View History

/*
*
* List reducer
*
*/
import { fromJS } from 'immutable';
import {
SET_CURRENT_MODEL_NAME,
2017-01-23 20:04:12 +01:00
LOAD_RECORDS,
2017-04-11 11:34:59 +02:00
LOADED_RECORDS,
LOAD_COUNT,
LOADED_COUNT,
2017-04-11 11:53:00 +02:00
CHANGE_PAGE,
2017-04-11 13:44:47 +02:00
CHANGE_SORT,
} from './constants';
2017-01-23 20:04:12 +01:00
const initialState = fromJS({
currentModel: null,
2017-04-11 11:34:59 +02:00
loadingRecords: true,
records: false,
2017-04-11 11:34:59 +02:00
loadingCount: true,
count: false,
currentPage: 1,
limitPerPage: 10,
2017-04-11 13:44:47 +02:00
sort: 'id',
2017-01-23 20:04:12 +01:00
});
function listReducer(state = initialState, action) {
switch (action.type) {
case SET_CURRENT_MODEL_NAME:
2017-01-23 20:04:12 +01:00
return state
.set('currentModelName', action.modelName);
case LOAD_RECORDS:
return state
2017-04-11 11:34:59 +02:00
.set('loadingRecords', true);
2017-01-23 20:04:12 +01:00
case LOADED_RECORDS:
return state
2017-04-11 11:34:59 +02:00
.set('loadingRecords', false)
.set('records', action.records);
2017-04-11 11:34:59 +02:00
case LOAD_COUNT:
return state
.set('loadingCount', true);
case LOADED_COUNT:
return state
.set('loadingCount', false)
.set('count', action.count);
2017-04-11 11:53:00 +02:00
case CHANGE_PAGE:
2017-04-11 11:34:59 +02:00
return state
2017-04-11 11:53:00 +02:00
.set('currentPage', action.page);
2017-04-11 13:44:47 +02:00
case CHANGE_SORT:
return state
.set('sort', action.sort);
default:
return state;
}
}
export default listReducer;