Skip to content

Commit

Permalink
fix: hoodie.trigger() should accept optional arguments (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnowoel authored and gr2m committed Aug 8, 2017
1 parent 7eb0da2 commit 84cf346
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ function off (state, eventName, handler) {
/**
* trigger a specified event
*
* @param {String} eventName Name of event
* @param {String} eventName Name of event
* @param {...*} [options] Options
*/
function trigger (state, eventName) {
state.emitter.emit(eventName)
var args = [].slice.call(arguments, 1)

state.emitter.emit.apply(state.emitter, args)

return this
}
21 changes: 21 additions & 0 deletions tests/specs/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,24 @@ test('"trigger" returns an object', function (t) {

t.is(typeof hoodie.trigger('account:signin'), 'object', 'returns an object')
})

test('"trigger" accepts optional arguments', function (t) {
t.plan(3)

var hoodie = new Hoodie({
PouchDB: PouchDBMock,
url: 'http://localhost:1234/hoodie'
})

var option1 = 'option1'
var option2 = 'option2'
var option3 = 'option3'

hoodie.on('account:signin', function () {
t.equal(arguments[0], option1, 'receives the first argument')
t.equal(arguments[1], option2, 'receives the second argument')
t.equal(arguments[2], option3, 'receives the third argument')
})

hoodie.trigger('account:signin', option1, option2, option3)
})

0 comments on commit 84cf346

Please sign in to comment.