mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 143 forks source link

Avoid multiple subscriptions of same callback to same topic #39

Closed FlyingDR closed 12 years ago

FlyingDR commented 12 years ago

As of AmplifyJS v1.1.0 there is no check performed about if given callback is already subscribed to the topic. It leads to a problem of several calls to same callback upon message publishing. Possible way to avoid it is to add some kind of checking of callbacks uniqueness e.g. by using some kind of hash function for them.

scottgonzalez commented 12 years ago

You shouldn't bind multiple times if you don't want to listen multiple times.

FlyingDR commented 12 years ago

It is not always possible to know if some callback is already bind, for example if it came as part of response on additional XHR request from server.

scottgonzalez commented 12 years ago

That's an issue in your application completely unrelated to pub/sub. If you have that problem, that means you never know if any code has been run for any type of initialization, which you need to solve some other way.