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 */ ) {
var inspected = {},
dataType = dataType || options.dataTypes[ 0 ]; seekingTransport = ( structure === transports );
inspected = inspected || {};
function inspect( dataType ) {
inspected[ dataType ] = true; var selected;
inspected[ dataType ] = true;
var selection, jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
list = structure[ dataType ], var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
i = 0, if( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
length = list ? list.length : 0, options.dataTypes.unshift( dataTypeOrTransport );
executeOnly = ( structure === prefilters ); inspect( dataTypeOrTransport );
return false;
for ( ; i < length && ( executeOnly || !selection ); i++ ) { } else if ( seekingTransport ) {
selection = list[ i ]( options, originalOptions, jqXHR ); return !( selected = dataTypeOrTransport );
// 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
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 inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
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