Fix event callbacks not being passed any arguments

This commit is contained in:
Samuel Elliott 2018-03-31 17:38:11 +01:00
parent c701a2b5f9
commit 0e14d167dc
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 3 additions and 2 deletions

View File

@ -23,14 +23,14 @@ export default class EventsWrapper {
get on() { return this.subscribe } get on() { return this.subscribe }
subscribe(event, callback) { subscribe(event, callback) {
if (this.eventSubs.find(e => e.event === event && e.callback === callback)) return; if (this.eventSubs.find(e => e.event === event && e.callback === callback)) return;
const boundCallback = () => callback.apply(this.bind, arguments); const boundCallback = (...args) => callback.apply(this.bind, args);
this.eventSubs.push({ event, callback, boundCallback }); this.eventSubs.push({ event, callback, boundCallback });
eventemitters.get(this).on(event, boundCallback); eventemitters.get(this).on(event, boundCallback);
} }
once(event, callback) { once(event, callback) {
if (this.eventSubs.find(e => e.event === event && e.callback === callback)) return; if (this.eventSubs.find(e => e.event === event && e.callback === callback)) return;
const boundCallback = () => this.off(event, callback) && callback.apply(this.bind, arguments); const boundCallback = (...args) => this.off(event, callback) && callback.apply(this.bind, args);
this.eventSubs.push({ event, callback, boundCallback }); this.eventSubs.push({ event, callback, boundCallback });
eventemitters.get(this).on(event, boundCallback); eventemitters.get(this).on(event, boundCallback);
} }
@ -50,4 +50,5 @@ export default class EventsWrapper {
} }
this.eventSubs.splice(0, this.eventSubs.length); this.eventSubs.splice(0, this.eventSubs.length);
} }
} }