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) => {
 console.log(event)
})

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

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

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

Another aspect of the event object is to provide access to Reshuffle common services:

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

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

Here is and example of a handler accessing the logger:

connector.on({interval:5000}, (event) => {
  logger.info('an info');
  logger.warn('a warning');
  logger.error('an error');
})