Commit 40f9ab9c authored by jaubourg's avatar jaubourg

better, more maintainable version of the prefilters execution and transport selection

parent 7d2e99fb
...@@ -88,43 +88,28 @@ function addToPrefiltersOrTransports( structure ) { ...@@ -88,43 +88,28 @@ function addToPrefiltersOrTransports( structure ) {
} }
// Base inspection function for prefilters and transports // Base inspection function for prefilters and transports
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR, function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
dataType /* internal */, inspected /* internal */ ) {
dataType = dataType || options.dataTypes[ 0 ]; var inspected = {},
inspected = inspected || {}; seekingTransport = ( structure === transports );
function inspect( dataType ) {
var selected;
inspected[ dataType ] = true; inspected[ dataType ] = true;
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
var selection, var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
list = structure[ dataType ], if( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
i = 0, options.dataTypes.unshift( dataTypeOrTransport );
length = list ? list.length : 0, inspect( dataTypeOrTransport );
executeOnly = ( structure === prefilters ); return false;
} else if ( seekingTransport ) {
for ( ; i < length && ( executeOnly || !selection ); i++ ) { return !( selected = dataTypeOrTransport );
selection = list[ i ]( options, originalOptions, jqXHR );
// If we got redirected to another dataType
// we try there if executing only and not done already
if ( typeof selection === "string" ) {
if ( !executeOnly || inspected[ selection ] ) {
selection = undefined;
} else {
options.dataTypes.unshift( selection );
selection = inspectPrefiltersOrTransports(
structure, options, originalOptions, jqXHR, selection, inspected );
}
} }
});
return selected;
} }
// If we're only executing or nothing was selected
// we try the catchall dataType if not done already return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
selection = inspectPrefiltersOrTransports(
structure, options, originalOptions, jqXHR, "*", inspected );
}
// unnecessary when only executing (prefilters)
// but it'll be ignored by the caller in that case
return selection;
} }
// A special extend for ajax options // A special extend for ajax options
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment