@ciklum/xmess-repeater

0.1.1 • Public • Published

XMESS Repeater

XMESS plugin for repeating messages among few XMESS instances

Table of contents

  1. Description
  2. Usage
  3. API

Description


XMESS Repeater - module which provides functionality of binding/communication among many XMESS instances. Usualy we use only one XMESS instance on app, but when we works with multiple applications then can use repeater for communication among them.

Usage


  • Set private repository:

    npm config set registry https://registry.npmjs.org/:_authToken=5ea6cd25-4d7d-4def-9ae0-e09c52e5b9a5
  • Install XMESS Repeater:

    npm install @ciklum/xmess-repeater --save
  • Import XmessRepeater to file

    import { XmessRepeater } from '@ciklum/xmess-repeater';
    ...
  • Construct XmessRepeater with translatorId and repeaterCallback

    import { XmessRepeater } from '@ciklum/xmess-repeater';
    import { Xmess } from '@ciklum/xmess';
    
    const xmess = new Xmess();
    const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => {
        xmess.publish(path, payload)
    });
    
    xmess.onPublish((path, payload) => {
        xmessRepeater.publish(path, payload);
    })
    ...

API

  • .publish(path, payload) for to subscribed XMESS`s, where path is channelName and payload is data for publishing

    import { XmessRepeater } from '@ciklum/xmess-repeater';
    
    const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => {
        ...
    });
    
    xmessRepeater.publish('app-group/route:changed', { pathname: '/offer' })
    ...
  • .getMessage(path) for getting last message from channel by path

    import { XmessRepeater } from '@ciklum/xmess-repeater';
    
    const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => {
        ...
    });
    
    const message = xmessRepeater.getMessage('app-group/route:changed');
    // message = { pathname: '/offer' } 
    ...
  • .destroy() for remove repeater instance

    import { XmessRepeater } from '@ciklum/xmess-repeater';
    
    const xmessRepeater = new XmessRepeater('repeater-1', (path, payload) => {
        ...
    });
    
    xmessRepeater.destroy()
    ...

Readme

Keywords

none

Package Sidebar

Install

npm i @ciklum/xmess-repeater

Weekly Downloads

0

Version

0.1.1

License

ISC

Unpacked Size

11.2 kB

Total Files

4

Last publish

Collaborators

  • ciklum