Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import { eventChannel } from 'redux-saga';
  2. import { take, put } from 'redux-saga/effects';
  3.  
  4. import { delay } from '../../common';
  5. import createAction from '../../actionCreator';
  6. import { createApolloClient } from '../../../components/apolloClient';
  7. import { CONNECTION_STATUS } from '../../../components/apolloClient/constants';
  8.  
  9. export default function* gqlChannel(deviceId) {
  10. const channel = eventChannel(listener => {
  11. const apolloClient = createApolloClient(deviceId);
  12. const handleConnectionStatus = (data) => {
  13. listener(data);
  14. };
  15. apolloClient.emitter.on(CONNECTION_STATUS, handleConnectionStatus);
  16. // startListenToGraphQLMethods(apolloClient, deviceId, listener);
  17. // apolloClient.emitter.on('reconnect', startListenToGraphQLMethods(apolloClient, deviceId, listener));
  18. return () =>
  19. apolloClient.emitter.removeEventListener(CONNECTION_STATUS, handleConnectionStatus);
  20. });
  21. yield delay(2000);
  22. yield put(createAction(undefined, 'WIPE', { hovno: 1 }));
  23. while (true) {
  24. const action = yield take(channel);
  25. yield put(createAction(undefined, action.type, action.data, action.error));
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement