@p.aleks/stomp-subscriptions
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

DEPRECATED

Do not use in new projects.

Fork of @jaszczw/stomp-redux-subscriptions version, add types, minor changed.

Usage example

import { createWsChannel, getInstance } from './';
import { all, cancelled, put, take } from 'redux-saga/effects';
import { EventChannel } from 'redux-saga';

function getInstanceIfNeed() {
  return getInstance({
    transports: ['websocket' /* , 'xhr-streaming', 'xhr-pooling' */],
    getSocksJsEndpoint: () => {
      const { host } = document.location;
      return `//${host}/`;
    }
  });
}

function* watchChannelEvents(channel: EventChannel<any>) {
  while (true) {
    const event = yield take(channel);
    switch (event.type) {
      case 'ROOT_CONNECTED': {
        // put emitted channel event if needed
        yield put({
          type: 'ROOT_CONNECTED'
        });
        break;
      }
    }
  }
}

function* connectSaga() {
  const wsClient = getInstanceIfNeed();
  const channel = createWsChannel(wsClient);
  try {
    return yield watchChannelEvents(channel);
  } finally {
    if (yield cancelled()) {
      channel.close();
    }
  }
}

export default function* () {
  yield all([connectSaga()]);
}

/@p.aleks/stomp-subscriptions/

    Package Sidebar

    Install

    npm i @p.aleks/stomp-subscriptions

    Weekly Downloads

    0

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    13.3 kB

    Total Files

    17

    Last publish

    Collaborators

    • p.aleks