member_webapp/@overflow/sensor/store/detail/detail.reducer.ts
crusader d59d9379f9 ing
2018-05-24 15:44:13 +09:00

50 lines
822 B
TypeScript

import {
Read,
ReadFailure,
ReadSuccess,
ActionType,
Actions,
} from './detail.action';
import {
State,
initialState,
} from './detail.state';
import { Sensor } from '@overflow/commons-typescript/model/sensor';
export function reducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionType.Read: {
return {
...state,
error: null,
isPending: true,
};
}
case ActionType.ReadSuccess: {
return {
...state,
error: null,
isPending: false,
sensor: action.payload,
};
}
case ActionType.ReadFailure: {
return {
...state,
error: action.payload,
isPending: false,
sensor: null,
};
}
default: {
return state;
}
}
}