Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singleton subscription ? #98

Open
Sephi-Chan opened this issue Oct 12, 2011 · 0 comments
Open

Singleton subscription ? #98

Sephi-Chan opened this issue Oct 12, 2011 · 0 comments

Comments

@Sephi-Chan
Copy link

Hi,

I was wondering how to implement some kind of singleton subscription. Example:

$('body').delegate '#new_participation a', 'ajax:success', (event, data)->
  channel = "games/#{data.game.id}/joins"
  juggernaut.subscribe channel, (data)->
    console.log "Data received...", data

The problem : after each event, a new subscribtion is created and the log is called many times. To fix it:

$('body').delegate '#new_participation a', 'ajax:success', (event, data)->
  channel = "games/#{data.game.id}/joins"
  unless subscriptions[channel]
    subscriptions[channel] = true
    juggernaut.subscribe channel, (data)->
      console.log "Data received...", data
  else
    console.log "Already subscribed!"

I believe this need is really common so, do you mind if I send a pull request to add it at the library level?

Romain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant