Skip to content

Commit

Permalink
Switching Publisher.publish signature to (eventName, ...args).
Browse files Browse the repository at this point in the history
Used to be `(eventName, argsArray)`.
  • Loading branch information
domenic committed Jan 27, 2012
1 parent 886a78d commit 6a7fbb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/Publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,14 +65,16 @@ 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.");
}
if (options.events && options.events.indexOf(eventName) === -1) {
throw new Error('Tried to publish an unknown event "' + eventName + '".');
}

var args = slice(arguments, 1);

if (normalListeners.has(eventName)) {
callListenersFor(eventName, args, normalListeners);
}
Expand Down
2 changes: 1 addition & 1 deletion test/1 basicFunctionality.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 6a7fbb0

Please sign in to comment.