haxenme/NME — pull request #77 by muton (2013-05-05 09:07:05+00:00)
Title: Modified native EventDispatcher to conform to docs regarding event priority

Hi,
Hope this is useful - I haven't managed to figure out how to get your unit tests set up yet (new-ish to haxe etc) but this does appear to work as intended!

---

Expected behaviour is that higher priority listeners will be called first, and where two listeners have the same priority notification order will be the same as order of addition.

This change ensures the list is always sorted with the highest priority listeners first. It does the sorting on addition rather than dispatch, and it only re-sorts when a listener with a non-zero priority is added (a new zero-priority listener should be at the end of the list in any case).

There's a lot of null-checking in the sort event, perhaps there's no need for it.