@p.aleks/stomp-subscriptions
v0.0.2
Published
Do not use in new projects. Idea of creating subscriptions system with @stomp/stompjs
Downloads
4
Readme
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()]);
}