joliss/broccoli — pull request #53 by jnicklas (2014-03-05 08:45:42+00:00)
Title: Extract watcher into own file

This pull request extract the logic of watching for changes given a builder into its own file. I also made some changes to the architecture of this. Basically we save the promise that the builder returns, and then on every request, we call `then` on this promise. Whenever a change is detected, we overwrite the promise. This means that the state of the build is kept and synchronized through the watcher, removing the need for `synchronized`. I didn't make any changes to `lib/builder` aside from removing `synchronized` from it, but there's a huge diff because the indentation changed.

I also made the Watcher an EventEmitter so that error and change events can be handled. This hopefully allows it to be reused by other parts in the future.

There's still a bit of an ugly workaround in that we can't get the directory value directly from the promise, since we're using Hapi's directory handler thing, and the promise isn't unwrapped there.

My plan is to refactor the server into a connect middleware and throw out Hapi, imo this makes the server much more modular and re-usable. Do you agree?