Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created February 13, 2012 01:53
Show Gist options
  • Save indexzero/1812647 to your computer and use it in GitHub Desktop.
Save indexzero/1812647 to your computer and use it in GitHub Desktop.
Before and after proposal in broadway.

Before and After hooks in Broadway

There are two limitations in the current broadway implementation which this proposal intends to address:

  • Events emitted by broadway.App instances are not granular enough. Currently only these events are emitted:
    • init: Emitted when the App has completed initialization.
    • ['plugin', name, 'init']: Emitted when a given plugin has completed initialization.
    • ['plugin', name, 'error']: Emitted when there was an error initializing the given plugin.
    • ['broadway', 'logged']: Emitted when the application has logged a given message
  • It is not possible to run a specified function before or after a given plugin method or other broadway action. The need for this has become clear refactoring jitsu to use flatiron. These hooks need to support async actions as well as sync actions.

Proposal

  1. Standardize and increase the number of events emitted by broadway.App instances:
  2. Implement before and after hooks similar to resourceful.
  var app = new broadway.App();

  app.before('start', function (callback) {
    doSomethingAsync(callback);
  });
@pksunkara
Copy link

1 can be done and straight forward and I think it's a good idea.

2 can be done by first loading @jesusabdullah's hook plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment