Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function interpet(state: IStoreState, action: R2D2Action): IStoreState {
- switch (action.type) {
- case ADD_DEVICE:
- return {
- ...state, devices: state.devices.concat(randomDevice())
- };
- case REFRESH_DEVICES:
- fetch(`http://localhost:8080/devices`)
- .then(response => response.json().then(body => ({ response, body })))
- .then(({ response, body }) => {
- const devices = body as IDevices
- // dispatch(updateDevices(devices))
- });
- return state;
- case UPDATE_DEVICE:
- return {
- ...state, devices: state.devices.map(device => {
- if (device.deviceId === action.deviceId) {
- return { deviceId: device.deviceId, lastFA: action.lastFA }
- }
- return device
- })
- };
- case SET_DEVICES:
- return {
- ...state, devices: action.devices
- };
- }
- return state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement