documentcloud/backbone — pull request #683 by braddunbar (2011-10-21 13:49:18+00:00)
Title: nested trigger with unbind

Nested calls to trigger can cause event handlers to be skipped in the outer call because the callback list has been spliced in the inner call.

I've fixed this by leaving the blank areas in the callback list and filling them in with bind, posing two additional issues:

* __Memory use of callback lists with mostly null items:__ I've addressed this by deleting the removed handlers instead of setting them null.
* __Traversing mostly empty callback lists in trigger:__ I would like to use a for-in loop to cut out the unnecessary traversals, but it would require a clean Array.prototype and the overhead from Object.hasOwnProperty doesn't seem worth it. Another approach is to wait until all calls to trigger are complete (using a method similar to that of set) and then compact the list but that seems just as wasteful in cases when the list has no empty items. Also, perhaps compaction could still occur inline, but only when in the outermost call. Suggestions are welcome!