photonstorm/phaser — pull request #1388 by pnstickne (2014-12-01 04:08:51+00:00)
Title: Event-Signal object count optimization

There are a bunch of signals added for Sprites; more when input is
enabled. However, very few of these signals are ever actually used. While
the previous performance update related to Signals addressed the size of
each Signal object, this update is to reduce the number of Signal objects
as used by the Events type.

As a comparison the "Particle: Random Sprite" demo creates 3200+ Signals;
with this change there less than 70 signals created when running the same
demo. (Each Event creates at least 8 signals by default, and there is an
Event for each of the 400 particles.)

It does this by creating a signal proxy getter and a signal dispatch
proxy. When the event property (eg. onDestroy) is accessed a new Signal
object is created (and cached) as required. This ensures that no user code
has to perform an existance-check on the event property first.

When the Phaser game code needs to dispatch the event it uses
`event.onEvent$dispath(..)` instead of `event.onEvent.dispatch(..)`. This
special auto-generated method automatically takes care of checking for if
the Signal has been created and only dispatches the event if this is the
case.

The only known user-code change is that code can add to signal (eg.
onInput) events even when input is not enabled - this will allow some
previously invalid code run without throwing an exception sooner.