juggernaut
juggernaut copied to clipboard
Singleton subscription ?
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