derickbailey/backbone.marionette — pull request #80 by camr (2012-04-19 21:15:56+00:00)
Title: Support asynchronous ItemView.onRender

Hi Derick, I ran across this issue with ItemViews rendering prematurely recently.

Currently if you define an onRender() method for an ItemView, the events 'render' and 'item:rendered' can be sent before the onRender() method completes, if onRender() calls one or more asynchronous functions.

This is particularly important since the move to make ItemView.render() methods themselves asynchronous.

For example, I have a situation where an ItemView creates and renders several sub views (they are rendered in the onRender() method because they depend on the parent having created DOM elements for them to bind to). This commit allows onRender() to return a promise which will prevent the render() method from firing its render completed events and resolving its own promise until the SubViews have completed their rendering.

The included test fails before and passes after the addition.

FYI, I believe a similar situation exists for CollectionViews.