batmanjs/batman — pull request #767 by nickjs (2013-07-15 17:03:37+00:00)
Title: Rails-style Event Handlers

We've decided to make our event handlers a lot more consistent, and to standardize this consistency around the style that Rails uses. What do I mean by Rails style? `before_action` (formerly `before_filter`), `after_action`, etc. In batman.js, it looks like this:

```coffeescript
class MyController extends Batman.Controller
@beforeAction 'ensureUserIsAdmin'
@beforeAction -> alert('doing an action! also, never do this.')
@beforeAction 'doSomethingElseOnIndex', only: 'index'
```

This pull request defines a reusable mixin for these things, which we're calling `LifecycleEvents`. This pull request also updates `Batman.Controller` to use the new mixin and renames `beforeFilter` to `beforeAction`, to more closely follow Rails 4. I didn't update other classes in interest of keeping the PR more... nimble?

A subsequent pull request will fix all of the events in the new `Batman.View` and `Batman.Model`. Replacing the current lifecycle state machine in `Batman.Model` could be useful too. I'm inclined to think it would clean things up a bit without being breaking, but I haven't looked into it much. Thoughts, everyone?

@SoapyIllusions @pushrax @kristianpd for review. And anyone else who feels like :)