Skip to content

Commit 513eaa3

Browse files
committed
Merge pull request #75 from natural-affinity/fix-event-context
fix: event callback context
2 parents f9fbbb2 + bf51175 commit 513eaa3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
if (this.events.hasOwnProperty(event)) {
200200
each(this.events[event], function (callback) {
201201
preventDefault = callback.apply(this, args.slice(1)) === false || preventDefault;
202-
});
202+
}, this);
203203
}
204204
if (event != 'catchall') {
205205
args.unshift('catchAll');

test/eventsSpec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ describe('events', function() {
1717
expect(valid).toBeTruthy();
1818
});
1919

20+
it('should have a context of flow instance', function() {
21+
var context = null;
22+
flow.on('test', function () {
23+
context = this;
24+
});
25+
flow.fire('test');
26+
expect(context).toEqual(flow);
27+
});
28+
2029
it('should pass some arguments', function() {
2130
var valid = false;
2231
var argumentOne = 123;
@@ -101,4 +110,4 @@ describe('events', function() {
101110
expect(event).not.toHaveBeenCalled();
102111
});
103112
});
104-
});
113+
});

0 commit comments

Comments
 (0)