提交 eaa5fbcc 编写于 作者: K Kevin Ngo

don't use cache object to maintain duplicate requests structure

上级 23690f57
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import { Cache } from './Cache'; import { Cache } from './Cache';
import { DefaultLoadingManager } from './LoadingManager'; import { DefaultLoadingManager } from './LoadingManager';
var currentlyLoadingFiles = {};
function FileLoader( manager ) { function FileLoader( manager ) {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager; this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
...@@ -23,7 +25,7 @@ Object.assign( FileLoader.prototype, { ...@@ -23,7 +25,7 @@ Object.assign( FileLoader.prototype, {
var cached = Cache.get( url ); var cached = Cache.get( url );
if ( cached !== undefined && ! cached.loaderSubscriptions ) { if ( cached !== undefined ) {
scope.manager.itemStart( url ); scope.manager.itemStart( url );
...@@ -40,9 +42,9 @@ Object.assign( FileLoader.prototype, { ...@@ -40,9 +42,9 @@ Object.assign( FileLoader.prototype, {
} }
// If file is already in process of loading, wait for it to load. // 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 ); scope.load( url, onLoad, onProgress, onError );
...@@ -141,11 +143,14 @@ Object.assign( FileLoader.prototype, { ...@@ -141,11 +143,14 @@ Object.assign( FileLoader.prototype, {
} else { } else {
var loaderSubscriptions = [];
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
// Allow other file loaders to wait and subscribe on this request. if ( Cache.enabled ) {
Cache.add( url, { loaderSubscriptions: loaderSubscriptions } );
// Allow other file loaders to wait and subscribe on this request.
currentlyLoadingFiles[ url ] = [];
}
request.open( 'GET', url, true ); request.open( 'GET', url, true );
...@@ -181,10 +186,18 @@ Object.assign( FileLoader.prototype, { ...@@ -181,10 +186,18 @@ Object.assign( FileLoader.prototype, {
} }
// Tell other requests for the same file that the file has finished loading. if ( Cache.enabled ) {
for ( var i = 0; i < loaderSubscriptions.length; i ++ ) {
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 ); }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册