Advertisement
Guest User

Untitled

a guest
Jul 6th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export function interpet(state: IStoreState, action: R2D2Action): IStoreState {
  2.   switch (action.type) {
  3.     case ADD_DEVICE:
  4.       return {
  5.         ...state, devices: state.devices.concat(randomDevice())
  6.       };
  7.     case REFRESH_DEVICES:
  8.       fetch(`http://localhost:8080/devices`)
  9.         .then(response => response.json().then(body => ({ response, body })))
  10.         .then(({ response, body }) => {
  11.           const devices = body as IDevices
  12.           // dispatch(updateDevices(devices))
  13.         });
  14.       return state;
  15.      
  16.     case UPDATE_DEVICE:
  17.       return {
  18.         ...state, devices: state.devices.map(device => {
  19.           if (device.deviceId === action.deviceId) {
  20.             return { deviceId: device.deviceId, lastFA: action.lastFA }
  21.           }
  22.           return device
  23.         })
  24.       };
  25.     case SET_DEVICES:
  26.       return {
  27.         ...state, devices: action.devices
  28.       };
  29.     }
  30.   return state;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement