Skip to content

gking2224/stompjs-redux-saga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stompjs-redux-saga

This library makes it easy to configure stompjs client connection integrated with redux saga.

Under the hood it uses lower-level callback/saga integration library @animando/redux-saga-callback.

Usage

Define your api and associated routines (see redux-saga-routines):

export const publishRoutine = createRoutine('PUBLISH_SOMETHING');
export const incomingMessageRoutine = createRoutine('INCOMING_MESSAGE');

export const subscriptions = [
  {
    path: '/topic/incoming',
    routine: incomingMessageRoutine,
    convertPayload: (body) => JSON.parse(body),
  },
];

export const testPublishDefinitions = [
  {
    path: '/app/publish_something',
    routine: publishRoutine,
  },
];

Finally, provide details of your websocket endpoint, and run the saga:

import { createWsApiSaga } from '@animando/stompjs-redux-saga';
const stompConnectionConfig = {
  sockJsEndpoint: <endpoint>,
}

const wsSaga = createWsApiSaga(stompConnectionConfig, stompApiDefinition)

function* rootSaga() {
  yield fork(wsSaga);
}

Now you just dispatch publish actions:

publishRoutine.trigger('my payload');

and handle incoming subscription notifications as actions in your reducer like normal:

const reducer = (state = {}, {type, payload}) => {
  switch (type) {
    case: incomingMessageRoutine.SUCCESS:
      return {
        ...state,
        incomingMessage: payload,
      }

  }
}

About

Saga for managing stomp connections and messaging

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published