gamechanger/mongothon — pull request #25 by tleach (2014-02-07 17:35:31+00:00)
Title: Rewrite of events

## Summary of changes

This is a backward incompatible change to the Mongothon `Model` API.

- "Middleware" as a concept has been removed and replaced with a more general "Events" mechanism.
- Rather than being locked into the 4 hard-coded middleware events as previously, the interface has been generalized to allow any event type to be emitted and/or listened to.
- There are now many more events emitted by a model out-of-the-box, mostly relating to document lifecycle.
- Custom events are now supported.

## Upgrade notes

Any existing registration of middleware functions using the previous 4 registration functions should be changed as follows to preserve previous behaviour:

`MyModel.before_validate(my_handler)` --> `MyModel.on('will_validate', my_handler)`
`MyModel.after_validate(my_handler)` --> `MyModel.on('did_validate', my_handler)`
`MyModel.before_save(my_handler)` --> `MyModel.on('will_save', my_handler)`
`MyModel.after_save(my_handler)` --> `MyModel.on('did_save', my_handler)`