commit 8dc79c0fa76ad05a2dd3403f5b5a3fb7f2d3c5b3
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2016-02-23T03:26:52Z |
| subject | Prevent reloading the same class |
commit 8dc79c0fa76ad05a2dd3403f5b5a3fb7f2d3c5b3
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2016-02-23T03:26:52Z
Prevent reloading the same class
---
botanjs/src/System/Net/ClassLoader.js | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
diff --git a/botanjs/src/System/Net/ClassLoader.js b/botanjs/src/System/Net/ClassLoader.js
index 06223ae..16adf6e 100644
--- a/botanjs/src/System/Net/ClassLoader.js
+++ b/botanjs/src/System/Net/ClassLoader.js
@@ -47,21 +47,39 @@
if( !classes.join ) classes = [ classes ];
var excludes = BotanJS.getDef();
- // Excludes
- utils.objMap( excludes , function( v ) { return "-" + v; } );
- var loadc = null;
var onLoad = function( e )
{
if( classes.indexOf( e.data.name ) < 0 ) return;
handler( e.data.name );
};
+ // Handle the already loaded classes
+ var needed = [];
+ for( var i in classes )
+ {
+ var c = classes[i];
+ if( excludes.indexOf( c ) == -1 )
+ {
+ needed.push( c );
+ }
+ else
+ {
+ handler( c );
+ }
+ }
+
+ if( !needed.length ) return;
+
+ // Excludes
+ utils.objMap( excludes , function( v ) { return "-" + v; } );
+ var loadc = null;
+
var sp = mode ? { 'o': '/', 'r': '/' }[ mode ] : ',';
loadFile(
sapi
- , classes.join( sp ) + sp + excludes.join( sp )
+ , needed.join( sp ) + sp + excludes.join( sp )
, mode
);