Created
June 1, 2011 22:05
-
-
Save guiocavalcanti/1003454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Investigating this issue a realized some behaivor that may not be what is excpected. Assuming we have two presence channels (say p1 and p2) created by exstending a common channel (using Pusher.Util.extend) and doing p1.memmbers.add(member) also adds the member to p2.members. Trying to overcome my bad english, I made a simplified example. | |
var Pusher = {} | |
Pusher.Channel = function(channel_name){ | |
this.name = channel_name; | |
} | |
Pusher.Channel.prototype = { | |
init : function(){ return "prototype init"; } | |
} | |
Pusher.Channel.PresenceChannel = { | |
init : function() { return "presence channel init"; }, | |
members : { | |
count : 0, | |
increment : function(){ | |
this.count++; | |
} | |
} | |
} | |
Pusher.Util = { | |
extend: function(target, extensions){ | |
for(var i in extensions){ | |
target[i] = extensions[i] | |
} | |
return target; | |
} | |
} | |
var ch1 = new Pusher.Channel("channel 1"); | |
var ch2 = new Pusher.Channel("channel 2"); | |
ch1 = Pusher.Util.extend(ch1, Pusher.Channel.PresenceChannel); | |
ch2 = Pusher.Util.extend(ch2, Pusher.Channel.PresenceChannel); | |
ch1.members.increment(); | |
console.log(ch1.members.count); // 1 | |
console.log(ch2.members.count); // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment