Code | npm | Code sample
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()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)
},
)channelwill 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')