hoodiehq/hoodie-server — pull request #248 by janl (2014-03-07 13:31:16+00:00)
Title: Split hooks into static and dynamic hooks

The reason for the change is that we have contexts where a plugin
needs access to a full `hoodie` instance, like a web hook that
wants to record the HTTP body into CouchDB. I call these dynamic
hooks, but I am happy to bikeshed this.

Another type of hook are ones that do not depend on a full `hoodie`
instance, for example ones, that we use to augment the hoodieServer
before starting it up. I call them static hooks, again, happy to
bikeshed.

Another difference between the hooks is that they are initialised
at different places in the lifecycle of hoodie-server:

- static hooks are initialised when plugins are read but before
the Hapi server gets started.
- dunamic hooks are initialised, after everything is started,
so they can expect a fully running Hoodie to do their work.

In order to make this easy to understand for plugin authors, I
changed the place for defining hooks from the top level
`hooks.js` to a top level directory `hooks/` with two files,
`static.js` and `dynamic.js`. Either file and the hooks
directory are optional.

This isn’t as pretty as I had hoped it could be, but I don’t see
a way around this, and it is still not too hard to understand.

See hoodiehq/hoodie-plugin-debug-email for an exmaple plugin.