Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add loader
  • Loading branch information
dafeng committed Sep 8, 2013
1 parent 2a0685a commit bcb6f41
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
23 changes: 14 additions & 9 deletions 1.0.0/bin/aml.js
Expand Up @@ -2,7 +2,7 @@
* aml.js v1.0.0
*
* A simple asynchronous module loader with dependency management.
* Latest build : 2013-09-08 13:39:38
* Latest build : 2013-09-08 14:04:42
*
* http://xudafeng.github.com/aml/
* ================================================================
Expand Down Expand Up @@ -210,7 +210,11 @@
var _uri = config.path ? config.path : LOC.href;
return _uri;
};

/**
* loader构造器
* @param id
* @constructor
*/
function Loader(id){
this.id = id;
this.pwd = parseUri();
Expand Down Expand Up @@ -283,19 +287,21 @@
});
}
,require:function(name){
return '';
Broadcast.fire('load',name);
return null;
}
,exec:function(d){
data[d.id]['instance'] = data[d.id]['constructor'].apply(this, d.depsMods) || {};
/**
* 执行行为触发数据变化,需要检测
*/
Broadcast.fire('check', data);
}
,load:function(d){
/**
* 并发加载模块队列
*/
each(d.mods,function(i){
new Loader(i);
});
new Loader(d);
}
,save:function(d){
/**
Expand Down Expand Up @@ -341,8 +347,8 @@
/**
* 加载即需模块
*/
Broadcast.fire('load',{
mods:_preLoadMods
each(_preLoadMods,function(i){
Broadcast.fire('load',i);
});
/**
* 推送检测模块
Expand All @@ -356,7 +362,6 @@
* 订阅defined事件
*/
Broadcast.on('define',function(d){

/**
* map赋值
* @type {*}
Expand Down
2 changes: 1 addition & 1 deletion 1.0.0/bin/aml.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 1.0.0/bin/aml.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions 1.0.0/example/test/mods/mod3.js
Expand Up @@ -2,6 +2,10 @@ define('mod3',[],function(){
console.log('add mod3')
var mod3 = function(){
console.log('mod3')
setTimeout(function(){
var xuyao = require('mod4');
console.log(xuyao)
},5000)
}
return mod3;
});
11 changes: 5 additions & 6 deletions 1.0.0/src/module.js
Expand Up @@ -25,7 +25,8 @@
});
}
,require:function(name){
return '';
Broadcast.fire('load',name);
return null;
}
,exec:function(d){
data[d.id]['instance'] = data[d.id]['constructor'].apply(this, d.depsMods) || {};
Expand All @@ -38,9 +39,7 @@
/**
* 并发加载模块队列
*/
each(d.mods,function(i){
new Loader(i);
});
new Loader(d);
}
,save:function(d){
/**
Expand Down Expand Up @@ -86,8 +85,8 @@
/**
* 加载即需模块
*/
Broadcast.fire('load',{
mods:_preLoadMods
each(_preLoadMods,function(i){
Broadcast.fire('load',i);
});
/**
* 推送检测模块
Expand Down
6 changes: 5 additions & 1 deletion 1.0.0/src/util/loader.js
Expand Up @@ -13,7 +13,11 @@
var _uri = config.path ? config.path : LOC.href;
return _uri;
};

/**
* loader构造器
* @param id
* @constructor
*/
function Loader(id){
this.id = id;
this.pwd = parseUri();
Expand Down

0 comments on commit bcb6f41

Please sign in to comment.