Skip to content

Instantly share code, notes, and snippets.

@pavelpower
Created November 13, 2013 19:17
Show Gist options
  • Save pavelpower/7454696 to your computer and use it in GitHub Desktop.
Save pavelpower/7454696 to your computer and use it in GitHub Desktop.
Bind n ready for sockets
bindOnSocketCanal: function(name, fn, scope) {
if (!window.now) {
console && console.error('sockets is not worked');
return;
}
now.ready(function() {
if (!now[name]) {
// if not canal then create
global._socketCanals[name] = [];
now[name] = function() {
var arr_fn = global._socketCanals[name],
i = 0, len = arr_fn.length;
for(; i < len; i++) {
arr_fn[i].fn.apply(arr_fn[i].scope, arguments);
}
};
}
global._socketCanals[name].push({
fn: fn,
scope: scope || this
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment