batmanjs/batman — pull request #914 by nsimmons (2013-11-27 14:50:53+00:00)
Title: Handle dead iterator binding and backing view

When an iterator binding is created and destroyed before the setImmediate callback if fired a JS error will occur because the backing view has been destroyed.

I have been able to identify one scenario where this happens. If you render a page that contains an iterator binding inside another iterator binding, and then update the collection that the outer iterator binding is binded to. The inner binding will be destroyed because the outer binding will recreate the contents of it's subviews.

This fix handles 2 cases:
- If the iterator binding is destroyed before the setImmediate is called, then die() will prevent the callback from being fired.
- If the Iterator's subview has been destroyed but the binding has not and setImmediate gets fired, we check that the backing view is not dead before trying to insert it into the DOM.

This is related to #904, and I still need to investigate why there is a race condition between the iterator's die() and setImmediate callback being fired. But for now this will prevent the error and instead return a warning.

@pushrax @kristianpd