Skip to content
Browse files

Switching `Publisher.publish` signature to `(eventName, ...args)`.

Used to be `(eventName, argsArray)`.
  • Loading branch information...
1 parent 886a78d commit 6a7fbb05ad9a72845dcf28207afd26bb2747dc12 @domenic committed
Showing with 11 additions and 2 deletions.
  1. +10 −1 lib/Publisher.js
  2. +1 −1 test/1 basicFunctionality.coffee
View
11 lib/Publisher.js
@@ -24,6 +24,13 @@ function normalizeOptions(options) {
return options;
}
+var slice = (function () {
+ var bind = Function.prototype.bind;
+ var uncurryThis = bind.bind(bind.call);
+
+ return uncurryThis(Array.prototype.slice);
+}());
+
module.exports = function Publisher(options) {
var that = this;
@@ -58,7 +65,7 @@ module.exports = function Publisher(options) {
var callListenersFor = options.async ? callListenersForAsync : callListenersForSync;
- that.publish = function (eventName, args) {
+ that.publish = function (eventName) {
if (typeof eventName !== "string") {
throw new TypeError("eventName argument must be a string.");
}
@@ -66,6 +73,8 @@ module.exports = function Publisher(options) {
throw new Error('Tried to publish an unknown event "' + eventName + '".');
}
+ var args = slice(arguments, 1);
+
if (normalListeners.has(eventName)) {
callListenersFor(eventName, args, normalListeners);
}
View
2 test/1 basicFunctionality.coffee
@@ -24,7 +24,7 @@ describe "Publisher/emitter under normal usage", ->
sinon.assert.calledOnce(listener)
it "should call the subscribing listener with the supplied arguments when the event is published with arguments", ->
- publisher.publish("eventName", [1, "foo"])
+ publisher.publish("eventName", 1, "foo")
sinon.assert.calledWithExactly(listener, 1, "foo")

0 comments on commit 6a7fbb0

Please sign in to comment.
Something went wrong with that request. Please try again.