Merge pull request #804 from friday/ads-trigger-arguments

[v3] Add optional arguments to Ads.trigger
This commit is contained in:
Sam Potts 2018-03-11 10:55:29 +11:00 committed by GitHub
commit 9a0c1c830d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,8 +50,9 @@ class Ads {
})
.catch(() => {
// Script failed to load or is blocked
this.trigger('ERROR');
this.player.debug.error('Google IMA SDK failed to load');
const message = 'Google IMA SDK failed to load';
this.trigger('ERROR', new Error(message));
this.player.debug.error(message);
});
} else {
this.ready();
@ -518,13 +519,13 @@ class Ads {
* Handles callbacks after an ad event was invoked
* @param {string} event - Event type
*/
trigger(event) {
trigger(event, ...args) {
const handlers = this.events[event];
if (utils.is.array(handlers)) {
handlers.forEach(handler => {
if (utils.is.function(handler)) {
handler.call(this);
handler.apply(this, args);
}
});
}