aleclarson / emitter-kit

Type-safe event handling for Swift
MIT License
566 stars 70 forks source link

Question about .on vs .once #3

Closed malkomalko closed 9 years ago

malkomalko commented 9 years ago

I've been playing around with the library, and after reading up on the README it looks like anytime you use .on vs .once for anything (in my case KVO), you have to push the listener into an array.

I was trying out .on without pushing on an array and everything looked fine. Can you explain a little more how this works out, and why I shouldn't be using .on without pushing into an array? Also, is there any cleanup I have to do for .on instead of .once?

Thanks

aleclarson commented 9 years ago

Everything works correctly now! That was a regression in v3.0 so thanks a lot! :thumbsup:

malkomalko commented 9 years ago

Hey @aleclarson can you explain what was a regression? Basically, if I use .on for anything, store the callback in an array, and do nothing else? Or do you mean everything works correctly in that I can use .on and .once in the same way?

Cheers,

Awesome library btw.

aleclarson commented 9 years ago

Glad you like it! Check out my other Swift repos, they might help you out. :smile:

Any Listener you create using on() must be retained. Otherwise, it's released at the end of your function. This was just fixed in v3.1 to work as expected. :thumbsup:

Any Listener created with once() is retained for you! So fire and forget.

Thanks for making an issue, @malkomalko!