mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 16:52:53 +08:00
fix(): add the reject function at the expected errorIndex position in the args array (#436)
We don't want that the reject cb takes the position of an optional argument that has not been defined For example the Dialogs.alert method takes an optional 'buttonLabel' string. In case we do not set this value, and thus want to use the default value, the 'reject' callback get spliced into this position due the fact that the splice start index is bigger than the array length. Dialogs.alert("title", "message", "My button text") --> args = ["title", resolve, "message", "My button text", reject] Dialogs.alert("title", "message") --> args = ["title", resolve, "message", reject] --> reject is on the position of the buttontitle! The cordova-plugin-dialogs alert function receives the wrong arguments —> alert: function(message, completeCallback, title, buttonLabel) The buttonLabel will receive the "reject" callback instead of a undefined value.
This commit is contained in:
parent
95e256293f
commit
4e87ac72ea
@ -51,7 +51,13 @@ function setIndex(args: any[], opts: any = {}, resolve?: Function, reject?: Func
|
||||
} else if (typeof opts.successIndex !== 'undefined' || typeof opts.errorIndex !== 'undefined') {
|
||||
// If we've specified a success/error index
|
||||
args.splice(opts.successIndex, 0, resolve);
|
||||
args.splice(opts.errorIndex, 0, reject);
|
||||
|
||||
// We don't want that the reject cb gets spliced into the position of an optional argument that has not been defined and thus causing non expected behaviour.
|
||||
if (opts.errorIndex > args.length) {
|
||||
args[opts.errorIndex] = reject; //insert the reject fn at the correct specific index
|
||||
} else {
|
||||
args.splice(opts.errorIndex, 0, reject); //otherwise just splice it into the array
|
||||
}
|
||||
} else {
|
||||
// Otherwise, let's tack them on to the end of the argument list
|
||||
// which is 90% of cases
|
||||
|
Loading…
Reference in New Issue
Block a user