diff options
| author | tunnckoCore <[email protected]> | 2017-01-18 02:35:13 +0200 |
|---|---|---|
| committer | tunnckoCore <[email protected]> | 2017-01-18 02:35:13 +0200 |
| commit | f4c60f4dd35fb875649c99b854bbb5c3aac72fdb (patch) | |
| tree | 3c110825af6f4b361b4e171dc793e88e99b737a3 | |
| parent | e814a573d827be5ebf9d3015ae606780d3f22eb3 (diff) | |
remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | src/index.js | 9 | ||||
| -rw-r--r-- | test/index.js | 16 |
3 files changed, 9 insertions, 19 deletions
@@ -68,8 +68,7 @@ If present, `"*"` handlers are invoked prior to type-matched handlers. **Parameters** - `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke -- `arg1` **\[Any]** A value (first argument), passed to each handler -- `arg2` **\[Any]** A value (second argument), passed to each handler +- `evt` **\[Any]** Any value (object is recommended and powerful), passed to each handler Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining diff --git a/src/index.js b/src/index.js index a67efb2..c4147c1 100644 --- a/src/index.js +++ b/src/index.js @@ -39,14 +39,13 @@ export default function mitt () { * If present, `"*"` handlers are invoked prior to type-matched handlers. * * @param {String} type The event type to invoke - * @param {Any} [arg1] A value (first argument), passed to each handler - * @param {Any} [arg2] A value (second argument), passed to each handler + * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler * @return {Object} the `mitt` instance for chaining * @memberof mitt */ - emit(type, arg1, arg2) { - (all[type] || []).map((handler) => { handler(arg1, arg2); }); - (all['*'] || []).map((handler) => { handler(type, arg1, arg2); }); + emit(type, evt) { + (all[type] || []).map((handler) => { handler(evt); }); + (all['*'] || []).map((handler) => { handler(type, evt); }); return ret; } }; diff --git a/test/index.js b/test/index.js index f552392..7c5c429 100644 --- a/test/index.js +++ b/test/index.js @@ -111,14 +111,6 @@ describe('mitt#', () => { inst.emit('foo', event); }); - it('should invoke handler with multiple (max 2) arguments', () => { - inst.on('foo', (aaa, bbb) => { - expect(aaa).to.be.equal(111); - expect(bbb).to.be.equal(222); - }); - inst.emit('foo', 111, 222); - }); - it('should NOT ignore case', () => { let foo = spy(), bar = spy(), @@ -134,8 +126,8 @@ describe('mitt#', () => { expect(foo).to.have.been.calledOnce; expect(bar).to.have.been.calledOnce; - expect(args1).to.be.deep.equal([num, undefined]); - expect(args2).to.be.deep.equal([num, undefined]); + expect(args1).to.be.deep.equal([num]); + expect(args2).to.be.deep.equal([num]); }); it('should invoke * handlers', () => { @@ -150,8 +142,8 @@ describe('mitt#', () => { args2 = star.args[1]; expect(star).to.have.been.calledTwice; - expect(args1).to.deep.equal(['foo', aa, undefined]); - expect(args2).to.deep.equal(['bar', aa, undefined]); + expect(args1).to.deep.equal(['foo', aa]); + expect(args2).to.deep.equal(['bar', aa]); }); }); }); |
