From eaa5fbcc679313409876bb7356a9a48bfc3633b1 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Wed, 18 Oct 2017 18:49:17 -0700 Subject: [PATCH] don't use cache object to maintain duplicate requests structure --- src/loaders/FileLoader.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/loaders/FileLoader.js b/src/loaders/FileLoader.js index 533555a720..ebc3ecfc9a 100644 --- a/src/loaders/FileLoader.js +++ b/src/loaders/FileLoader.js @@ -5,6 +5,8 @@ import { Cache } from './Cache'; import { DefaultLoadingManager } from './LoadingManager'; +var currentlyLoadingFiles = {}; + function FileLoader( manager ) { this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager; @@ -23,7 +25,7 @@ Object.assign( FileLoader.prototype, { var cached = Cache.get( url ); - if ( cached !== undefined && ! cached.loaderSubscriptions ) { + if ( cached !== undefined ) { scope.manager.itemStart( url ); @@ -40,9 +42,9 @@ Object.assign( FileLoader.prototype, { } // If file is already in process of loading, wait for it to load. - if ( cached !== undefined && cached.loaderSubscriptions ) { + if ( currentlyLoadingFiles[ url ] !== undefined ) { - cached.loaderSubscriptions.push( function () { + currentlyLoadingFiles[ url ].push( function () { scope.load( url, onLoad, onProgress, onError ); @@ -141,11 +143,14 @@ Object.assign( FileLoader.prototype, { } else { - var loaderSubscriptions = []; var request = new XMLHttpRequest(); - // Allow other file loaders to wait and subscribe on this request. - Cache.add( url, { loaderSubscriptions: loaderSubscriptions } ); + if ( Cache.enabled ) { + + // Allow other file loaders to wait and subscribe on this request. + currentlyLoadingFiles[ url ] = []; + + } request.open( 'GET', url, true ); @@ -181,10 +186,18 @@ Object.assign( FileLoader.prototype, { } - // Tell other requests for the same file that the file has finished loading. - for ( var i = 0; i < loaderSubscriptions.length; i ++ ) { + if ( Cache.enabled ) { + + var duplicateRequests = currentlyLoadingFiles[ url ]; + + delete currentlyLoadingFiles[ url ]; + + // Tell other requests for the same file that the file has finished loading. + for ( var i = 0; i < duplicateRequests.length; i ++ ) { + + duplicateRequests[i]( response ); - loaderSubscriptions[ i ]( response ); + } } -- GitLab