Comparing version 0.1.1 to 0.2.0
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
// Generated by CoffeeScript 1.4.0 | ||
@@ -12,3 +12,3 @@ /* | ||
(function() { | ||
var Channel, airwaves, remove, | ||
var Channel, airwaves, remove, split, | ||
__slice = [].slice, | ||
@@ -29,2 +29,21 @@ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
split = function(fn) { | ||
return function() { | ||
var args, n, names; | ||
names = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
return fn.call.apply(fn, [this, (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = names.split(/[,\s]+/); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
n = _ref[_i]; | ||
if (n) { | ||
_results.push(n); | ||
} | ||
} | ||
return _results; | ||
})()].concat(__slice.call(args))); | ||
}; | ||
}; | ||
Channel = (function() { | ||
@@ -37,69 +56,82 @@ | ||
Channel.prototype.intercept = function(name, fn) { | ||
var _base; | ||
((_base = this.subscriptions)[name] || (_base[name] = { | ||
ints: [], | ||
subs: [] | ||
})).ints.push(fn); | ||
}; | ||
Channel.prototype.intercept = split(function(names, fn) { | ||
var n, _base, _i, _len; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
n = names[_i]; | ||
((_base = this.subscriptions)[n] || (_base[n] = { | ||
ints: [], | ||
subs: [] | ||
})).ints.push(fn); | ||
} | ||
}); | ||
Channel.prototype.subscribe = function(name, fn) { | ||
var _base; | ||
((_base = this.subscriptions)[name] || (_base[name] = { | ||
ints: [], | ||
subs: [] | ||
})).subs.push(fn); | ||
}; | ||
Channel.prototype.subscribe = split(function(names, fn) { | ||
var n, _base, _i, _len; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
n = names[_i]; | ||
((_base = this.subscriptions)[n] || (_base[n] = { | ||
ints: [], | ||
subs: [] | ||
})).subs.push(fn); | ||
} | ||
}); | ||
Channel.prototype.unsubscribe = function(name, fn) { | ||
if (fn === void 0) { | ||
delete this.subscriptions[name]; | ||
} else if (Object.prototype.hasOwnProperty.call(this.subscriptions, name)) { | ||
remove(this.subscriptions[name].ints, fn); | ||
remove(this.subscriptions[name].subs, fn); | ||
Channel.prototype.unsubscribe = split(function(names, fn) { | ||
var name, _i, _len; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
name = names[_i]; | ||
if (fn === void 0) { | ||
delete this.subscriptions[name]; | ||
} else if (Object.prototype.hasOwnProperty.call(this.subscriptions, name)) { | ||
remove(this.subscriptions[name].ints, fn); | ||
remove(this.subscriptions[name].subs, fn); | ||
} | ||
} | ||
}; | ||
}); | ||
Channel.prototype.broadcast = function() { | ||
var args, name, next, queue, sub, wrap; | ||
name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
if (__indexOf.call(this.stack, name) >= 0) { | ||
return; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(this.subscriptions, name)) { | ||
return; | ||
} | ||
this.stack.push(name); | ||
queue = this.subscriptions[name].ints.slice(0); | ||
wrap = function(fn) { | ||
return function() { | ||
var args, next; | ||
next = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
fn.apply(null, args); | ||
return next.apply(null, args); | ||
Channel.prototype.broadcast = split(function() { | ||
var args, name, names, next, queue, sub, wrap, _i, _len; | ||
names = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
for (_i = 0, _len = names.length; _i < _len; _i++) { | ||
name = names[_i]; | ||
if (__indexOf.call(this.stack, name) >= 0) { | ||
continue; | ||
} | ||
if (!Object.prototype.hasOwnProperty.call(this.subscriptions, name)) { | ||
continue; | ||
} | ||
this.stack.push(name); | ||
queue = this.subscriptions[name].ints.slice(0); | ||
wrap = function(fn) { | ||
return function() { | ||
var args, next; | ||
next = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
fn.apply(null, args); | ||
return next.apply(null, args); | ||
}; | ||
}; | ||
}; | ||
queue.push.apply(queue, (function() { | ||
var _i, _len, _ref, _results; | ||
_ref = this.subscriptions[name].subs; | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
sub = _ref[_i]; | ||
_results.push(wrap(sub)); | ||
queue.push.apply(queue, (function() { | ||
var _j, _len1, _ref, _results; | ||
_ref = this.subscriptions[name].subs; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
sub = _ref[_j]; | ||
_results.push(wrap(sub)); | ||
} | ||
return _results; | ||
}).call(this)); | ||
next = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (queue.length) { | ||
return queue.shift().apply(null, [next].concat(__slice.call(args))); | ||
} | ||
}; | ||
try { | ||
next.apply(null, args); | ||
} finally { | ||
this.stack.pop(); | ||
} | ||
return _results; | ||
}).call(this)); | ||
next = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (queue.length) { | ||
return queue.shift().apply(null, [next].concat(__slice.call(args))); | ||
} | ||
}; | ||
try { | ||
next.apply(null, args); | ||
} finally { | ||
this.stack.pop(); | ||
} | ||
}; | ||
}); | ||
@@ -112,3 +144,3 @@ return Channel; | ||
Channel: Channel, | ||
version: '0.1.1' | ||
version: '0.2.0' | ||
}; | ||
@@ -115,0 +147,0 @@ |
{ | ||
"name": "airwaves", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"author": "David Chambers <dc@hashify.me>", | ||
@@ -12,6 +12,6 @@ "keywords": ["pubsub", "publish", "subscribe", "broadcast", "message"], | ||
"devDependencies": { | ||
"coffee-script": "1.3.x", | ||
"mocha": "1.6.x", | ||
"coffee-script": "1.4.x", | ||
"mocha": "1.7.x", | ||
"should": "1.2.x" | ||
} | ||
} |
@@ -126,2 +126,18 @@ # Airwaves | ||
### Event names | ||
Airwaves supports comma-separated event names, so the following snippets | ||
are equivalent: | ||
```coffeescript | ||
channel.subscribe 'numerator-change', calculate | ||
channel.subscribe 'denominator-change', calculate | ||
``` | ||
```coffeescript | ||
channel.subscribe 'numerator-change, denominator-change', calculate | ||
``` | ||
More accurately, event names are delimited by `[,\s]+` (thus cannot contain | ||
commas or whitespace). | ||
### Testing | ||
@@ -128,0 +144,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17334
133
146
1