Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 1.75 KB

File metadata and controls

83 lines (58 loc) · 1.75 KB

reshuffle

Code | npm | Code sample

Reshuffle Custom Event Connector

This package contains a Reshuffle connector that can fire a custom event. This event can be fired from a script.

The following example exposes an endpoint to return the data of a custom event after it was fired.

const { CustomEventConnector, Reshuffle } = require('reshuffle')

const app = new Reshuffle()

const connector = new CustomEventConnector(app)

connector.on(
    { channel:'channel-one' },
    (event) => {
      console.log('Custom Event One: ', event.payload)
    }
  )
  
  connector.on(
    { channel:'channel-two' },
    (event) => {
      console.log('Custom Event Two: ', event.payload)
    },
  )

app.start()

Table of Contents

Connector Events

Fire Custom Events

Events

Fire Event

Fire event is executed inside the developer's script, you'll need to capture it with the connector's on function, providing a CustomEventConnectorEventOptions to it.

interface CustomEventConnectorEventOptions {
  channel: string
}

Example:

connector.on(
  { channel:'channel-one' },
  (event) => {
    console.log('Custom Event One: ', event.payload)
  },
)

connector.on(
  { channel:'channel-two' },
  (event) => {
    console.log('Custom Event Two: ', event.payload)
  },
)
  • channel will be used to identify and fire the event.

Example:

  connector.fire('channel-one', { name: 'Jack', age: 25 })
  connector.fire('channel-two', 'A String to display')