Skip to content

Commit

Permalink
fix(this): update tests; listeners should not have "this" context
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Mar 17, 2017
1 parent 84b7e9a commit 534f7a3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/dush.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ function dush () {
emit: function emit (name) {
if (name !== '*') {
var args = [].slice.call(arguments);
(all[name] || []).map(function (handler) { handler.apply(app, args.slice(1)); });
(all['*'] || []).map(function (handler) { handler.apply(app, args); });
(all[name] || []).map(function (handler) { handler.apply(undefined, args.slice(1)); });
(all['*'] || []).map(function (handler) { handler.apply(undefined, args); });
}

return app
Expand Down
4 changes: 2 additions & 2 deletions dist/dush.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ function dush () {
emit: function emit (name) {
if (name !== '*') {
var args = [].slice.call(arguments);
(all[name] || []).map(function (handler) { handler.apply(app, args.slice(1)); });
(all['*'] || []).map(function (handler) { handler.apply(app, args); });
(all[name] || []).map(function (handler) { handler.apply(undefined, args.slice(1)); });
(all['*'] || []).map(function (handler) { handler.apply(undefined, args); });
}

return app
Expand Down
2 changes: 1 addition & 1 deletion dist/dush.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/dush.umd.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dush.umd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ export default function dush () {
emit (name) {
if (name !== '*') {
var args = [].slice.call(arguments);
(all[name] || []).map((handler) => { handler.apply(app, args.slice(1)) });
(all['*'] || []).map((handler) => { handler.apply(app, args) })
(all[name] || []).map((handler) => { handler.apply(undefined, args.slice(1)) });
(all['*'] || []).map((handler) => { handler.apply(undefined, args) })
}

return app
Expand Down
13 changes: 13 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,16 @@ test('should support to emit any number of arguments', function (done) {
})
.emit('zazzie', 1, 2, 3, 4, 5)
})

test('should event listeners not have `this` context', function (done) {
function listener (hi) {
test.strictEqual(hi, 'hello world')
test.strictEqual(this, undefined)
done()
}

var app = dush()
app.on('ctx', listener)
app.once('ctx', listener)
app.emit('ctx', 'hello world')
})

0 comments on commit 534f7a3

Please sign in to comment.