Shopify/batman — pull request #470 by hornairs (2012-06-18 13:59:00+00:00)
Title: Really after afterFilters

This change implements something which I think makes sense, but I solicit everyones opinion on: make Controller `afterFilter`s execute after their respective actions have been taken. In context, this means that the afterFilters on an action won't run until rendering and/or other actions executed with `executeAction` have completed.

The use case for this popped up with the hash-routing stuff. I implemented an `afterFilter` on `Batman.Controller` which says "scroll to the element with ID = params['#'] if it exists and this functionality is enabled". All controllers inherit this so it should just work. The problem is this `afterFilter` executes before the view rendered by the controller has even started to render, which means the element with the ID will never exists. In more general terms: you can't expect to work with the DOM in `afterFilters` before this patch, which I think is lame.

So, to accomplish the waiting around for the actions to complete within the potentially nested structure of actions, I introduce a new class, the `ControllerActionFrame`, which counts how many outstanding actions there are and calls a callback when they are all done. That callback is what the controller uses to call the after filters and other teardown stuff.

@nciagra @jamesmacaulay for review please, and anyone else feel free to pipe in!