The Event Class

Reshuffle apps are event driven, so the event object plays a key role in the reshuffle app architecture.

The event class server to pass information from the connector into your event handler code:

s3Connector.on({ type: 'ObjectAdded' }, async (event, app) => {

By convention, event information passed from the controller to the handler resided in a event parameter.

Here is how an HTTPConnector event handler accesses the http res object:

connector.on({ method: 'GET', path: '/test' }, (event, app) => {
  event.res.end('Hello World!')

Another common task for the event handler is to access the Reshuffle common services, through the app object:

Here is how an event handler accesses the common datastore from the event object:

connector.on({ expression: '*/5 * * * * *' }, async (event, app) => {
  let store = app.getPersistentStore()
  // single server setup
  let times = (await store.get('scripts/times-said-hello')) || 0
  console.log(`Hello World! ${times} times.`)
  await store.set('scripts/times-said-hello', times)

Here is and example of a handler accessing the logger:

connector.on({ expression: '*/5 * * * * *' }, (event, app) => {'an info')
  logger.warn('a warning')
  logger.error('an error')