import {
  CONNECTED,
  MEMORY_STAT_RECEIVED,
  INVALID_MESSAGE_RECEIVED,
} from '../../../../shared/action-types';

import config from '../../../../shared/config';

const webSocketsMiddleware = (store) => {
  const socket = new WebSocket(config.websockets.address);

  socket.addEventListener('open', () => {
    store.dispatch({ type: CONNECTED });
  });

  socket.addEventListener('message', ({ data = '{}' }) => {
    let payload;

    try {
      payload = JSON.parse(data);
    } catch (err) {
      payload = {};
    }

    if ([MEMORY_STAT_RECEIVED].includes(payload.type)) {
      store.dispatch(payload);
    } else {
      store.dispatch({ type: INVALID_MESSAGE_RECEIVED, payload });
    }
  });
};

export default webSocketsMiddleware;

@@ -531,40 +531,8 @@
  if 
-(%5BMEMORY_STAT_RECEIVED%5D.includes
 (pay
@@ -541,17 +541,16 @@
 ad.type)
-)
  %7B%0A     

fix tests for c9