americano icon indicating copy to clipboard operation
americano copied to clipboard

Real hook system

Open jsilvestre opened this issue 10 years ago • 1 comments

Currently we have two hooks: beforeStart and afterStart. In my experience, it's not enough. I mean I never get what the hook I want where I want. Sometimes I need it before plugins are loaded, sometimes right after, .... so I end up not using beforeStart and afterStart (or rarely).

I suggest we turn americano (the object) into an event emitter that triggers events at each step of initialization:

  • before anything happens
  • before configuration loads
  • after configuration loads
  • before plugins are loaded
  • after each plugins has been loaded (with the plugin name)
  • after plugins are loaded
  • before routes are loaded
  • after routes are loaded
  • before http server actually starts
  • after http server actually starts
  • after everything happens

Many events are redundant here but this adds semantic. The callback for these events could be declared in an ./server/init.coffee file or in the configuration (if we feel the configuration events are not relevant).

jsilvestre avatar May 23 '14 08:05 jsilvestre

Good idea :+1: !

gelnior avatar May 25 '14 10:05 gelnior