description and source-codePushNotification = function (options) {
this._handlers = {
'registration': [],
'notification': [],
'error': []
};
// require options parameter
if (typeof options === 'undefined') {
throw new Error('The options argument is required.');
}
// store the options to this object instance
this.options = options;
// triggered on registration and notification
var that = this;
var success = function(result) {
if (result && typeof result.registrationId !== 'undefined') {
that.emit('registration', result);
} else if (result && result.additionalData && typeof result.additionalData.actionCallback !== 'undefined') {
var executeFuctionOrEmitEventByName = function(callbackName, context, arg) {
var namespaces = callbackName.split('.');
var func = namespaces.pop();
for (var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
if (typeof context[func] === 'function') {
context[func].call(context, arg);
} else {
that.emit(callbackName, arg);
}
};
executeFuctionOrEmitEventByName(result.additionalData.actionCallback, window, result);
} else if (result) {
that.emit('notification', result);
}
};
// triggered on error
var fail = function(msg) {
var e = (typeof msg === 'string') ? new Error(msg) : msg;
that.emit('error', e);
};
// wait at least one process tick to allow event subscriptions
setTimeout(function() {
exec(success, fail, 'PushNotification', 'init', [options]);
}, 10);
}