millermedeiros / js-signals

Custom Event/Messaging system for JavaScript inspired by AS3-Signals
http://millermedeiros.github.com/js-signals/
1.97k stars 179 forks source link

Minor Tweak to Signal Binding #24

Closed paullewis closed 13 years ago

paullewis commented 13 years ago

I was finding that if the SignalBinding was still set to active, but that the signal listener was removed it would execute against an undefined object.

I think it's because in the dispatch loop the binding exists but the actual listener may not. Obviously one may disable the binding but I just added the !!this._listener for safety :)

millermedeiros commented 13 years ago

nice catch, I will create a test to ensure it still work in the future and merge the changes. thanks.

millermedeiros commented 13 years ago

ohh, just realized why there is no check., I considered that _listener would be always available since the user isn't supposed to change it (variables starting with underscore are pseudo-private) and there is no way to create a binding without a listener

do you have any example on how to make it fail?

paullewis commented 13 years ago

Not now, no. The code I've got is for a client so I can't just push it up. But the general idea is this:

  1. Bind two listeners to a signal
  2. Dispatch the signal
  3. In the first listener unbind the second listener, or actually delete the object with the listener function in it

In this case the loop through in the dispatch expects the second binding to be there, which it is. But if the _listener property has been deleted it's going to bail, which is what happened for me :)

millermedeiros commented 13 years ago

makes sense and I will integrate it on the next few days and add tests that match your description. thanks!