1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-14 03:22:48 +00:00

handling sensors with redux

This commit is contained in:
2016-09-05 18:27:52 +00:00
parent be5e95b6cf
commit 0e8d2e5b2b
15 changed files with 200 additions and 69 deletions

View File

@@ -0,0 +1,59 @@
//import typs
import * as types from '../constants/sensor';
//defaults -
const defaultState = {
list : [],
infoMonth: [],
infoYear: [],
fetchingList: false,
fetchingInfoMonth: false,
fetchingInfoYear: false,
fetchedList: false,
fetchedInfoMonth: false,
fetchedInfoYear: false
};
//default reducer
export default function app(state = defaultState, action) {
switch(action.type){
case types.FETCHING_LIST:
return Object.assign({}, state, {
fetchingList: true,
fetchedList: false
});
case types.FETCHING_INFO_MONTH:
return Object.assign({}, state, {
fetchingInfoMonth: true,
fetchedInfoMonth: false
});
case types.FETCHING_INFO_YEAR:
return Object.assign({}, state, {
fetchingInfoYear: true,
fetchedInfoYear: false
});
case types.LOAD_SENSOR_LIST:
return Object.assign({}, state, {
list: action.sensor_list,
fetchingList: false,
fetchedList: true
});
case types.LOAD_SENSOR_INFO_MONTH:
return Object.assign({}, state, {
infoMonth: action.sensor_info,
fetchingInfoMonth: false,
fetchedInfoMonth: true
});
case types.LOAD_SENSOR_INFO_YEAR:
return Object.assign({}, state, {
infoYear: action.sensor_info,
fetchingInfoYear: false,
fetchedInfoYear: true
});
}
//return present state if no actions get called
return state;
}