Skip to content

Conversation

@WebnetMobile
Copy link

Patched bind() to check if given listener is not already bond to specified event. This solves problems with duplicates on i.e. reconnects

@ocram
Copy link
Contributor

ocram commented Jul 25, 2013

This can and should be made shorter:

if (!eventListeners.get(state).contains(eventListener)) { eventListeners.get(state).add(eventListener); } 
@WebnetMobile
Copy link
Author

No. It "might", but not "should". This is equivalent and produces the same bytecode.

@ocram
Copy link
Contributor

ocram commented Jul 25, 2013

It is more readable, shorter and avoids the creation of an additional (unnecessary) object.

Edit: I've just seen that you've changed it already :) Thank you!

@mdpye
Copy link
Contributor

mdpye commented Nov 18, 2013

Hi, thanks for you patch (and sorry for the delay in responding!)

However, duplicate handlers should not really be an issue, because you should set them up once, when you create the Pusher instance, but not again on reconnect. The Pusher instance maintains such state while it is disconnected and re-negotiates your channel subscriptions etc when it is reconnected, so you shouldn't have to re-register anything.

This also means that you can set up your channels and bindings before the initial call to connect(), meaning there's no need for logic to detect if this has already been done.

If you have a use case which this won't cover well, please open another issue with a note of it and I'll consider how we can accommodate it. I'd rather not expand the library API unnecessarily.

@mdpye mdpye closed this Nov 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants