Ext create动态加载分析
主要涉及到Ext.js Inventory.js ClassManager.js Class.js Loader.js Boot.js
在ClasManager.js的Ext.create中
Ext.syncRequire(name); // 加载类的js
Loader.js 中
syncRequire: function () {
var wasEnabled = Loader.syncModeEnabled;
Loader.syncModeEnabled = true;
var ret = Loader.require.apply(Loader, arguments);
Loader.syncModeEnabled = wasEnabled;
return ret;
},
require: function (expressions, fn, scope, excludes) {
if (excludes) {
return Loader.exclude(excludes).require(expressions, fn, scope);
}
var classNames = Manager.getNamesByExpression(expressions);
return Loader.load(classNames, fn, scope);
},
load: function (classNames, callback, scope) {
if (callback) {
if (callback.length) {
// If callback expects arguments, shim it with a function that will map
// the requires class(es) from the names we are given.
callback = Loader.makeLoadCallback(classNames, callback);
}
callback = callback.bind(scope || Ext.global);
}
var state = Manager.classState,
missingClassNames = [],
urls = [],
urlByClass = {},
numClasses = classNames.length,
url, className, i, numMissing;
for (i = 0; i < numClasses; ++i) {
className = Manager.resolveName(classNames[i]);
if (!Manager.isCreated(className)) {
missingClassNames.push(className);
if (!state[className]) {
urlByClass[className] = Loader.getPath(className);
urls.push(urlByClass[className]);
}
}
}
// If the dynamic dependency feature is not being used, throw an error
// if the dependencies are not defined
numMissing = missingClassNames.length;
if (numMissing) {
Loader.missingCount += numMissing;
Manager.onCreated(function () {
if (callback) {
Ext.callback(callback, scope, arguments);
}
Loader.checkReady();
}, Loader, missingClassNames);
if (!_config.enabled) {
Ext.raise("Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. " +
"Missing required class" + ((missingClassNames.length > 1) ? "es" : "") +
": " + missingClassNames.join(', '));
}
if (urls.length) {
Loader.loadScripts({
url: urls,
// scope will be this options object so we can pass these along:
_classNames: missingClassNames,
_urlByClass: urlByClass
});
}
else {
// need to call checkReady here, as the _missingCoun
// may have transitioned from 0 to > 0, meaning we
// need to block ready
Loader.checkReady();
}
}
else {
if (callback) {
callback.call(scope);
}
// need to call checkReady here, as the _missingCoun
// may have transitioned from 0 to > 0, meaning we
// need to block ready
Loader.checkReady();
}
if (Loader.syncModeEnabled) {
// Class may have been just loaded or was already loaded
if (numClasses === 1) {
return Manager.get(classNames[0]);
}
}
return Loader;
},
/**
* This is an internal method that delegate content loading to the
* bootstrap layer.
* @private
* @param params
*/
loadScripts: function(params) {
var manifest = Ext.manifest,
loadOrder = manifest && manifest.loadOrder,
loadOrderMap = manifest && manifest.loadOrderMap,
options; ++Loader.scriptsLoading; // if the load order map hasn't been created, create it now
// and cache on the manifest
if (loadOrder && !loadOrderMap) {
manifest.loadOrderMap = loadOrderMap = Boot.createLoadOrderMap(loadOrder);
} // verify the loading state, as this may have transitioned us from
// not loading to loading
Loader.checkReady(); options = Ext.apply({
loadOrder: loadOrder,
loadOrderMap: loadOrderMap,
charset: _config.scriptCharset,
success: Loader.onLoadSuccess,
failure: Loader.onLoadFailure,
sync: Loader.syncModeEnabled,
_classNames: []
}, params); options.userScope = options.scope;
options.scope = options; Boot.load(options);
},
在Boot.js中
load: function (request) {
//<debug>
// _debug("Boot.load called");
//</debug>
var request = new Request(request);
if (request.sync || Boot.syncMode) {
return Boot.loadSync(request);
}
// If there is a request in progress, we must
// queue this new request to be fired when the current request completes.
if (Boot.currentRequest) {
//<debug>
// _debug("current active request, suspending this request");
//</debug>
// trigger assignment of entries now to ensure that overlapping
// entries with currently running requests will synchronize state
// with this pending one as they complete
request.getEntries();
Boot.suspendedQueue.push(request);
} else {
Boot.currentRequest = request;
Boot.processRequest(request, false);
}
return Boot;
},
loadSync: function() {
var me = this;
me.fetch({
async: false,
complete: function (response) {
me.onContentLoaded(response);
}
});
me.evaluate();
me.notifyRequests();
},
fetch: function (req) {
var url = this.getLoadUrl(),
async = !!req.async,
complete = req.complete;
Boot.fetch(url, complete, this, async);
},
最终网络通讯在这
fetch: function(url, complete, scope, async) {
async = (async === undefined) ? !!complete : async;
var xhr = new XMLHttpRequest(),
result, status, content, exception = false,
readyStateChange = function () {
if (xhr && xhr.readyState == 4) {
status = (xhr.status === 1223) ? 204 :
(xhr.status === 0 && ((self.location || {}).protocol === 'file:' ||
(self.location || {}).protocol === 'ionp:')) ? 200 : xhr.status;
content = xhr.responseText;
result = {
content: content,
status: status,
exception: exception
};
if (complete) {
complete.call(scope, result);
}
xhr.onreadystatechange = emptyFn;
xhr = null;
}
};
if (async) {
xhr.onreadystatechange = readyStateChange;
}
try {
//<debug>
// _debug("fetching " + url + " " + (async ? "async" : "sync"));
//</debug>
xhr.open('GET', url, async);
xhr.send(null);
} catch (err) {
exception = err;
readyStateChange();
return result;
}
if (!async) {
readyStateChange();
}
return result;
},
notifyAll: function(entry) {
entry.notifyRequests();
}
};
complete函数定义在这
onContentLoaded: function (response) {
var me = this,
status = response.status,
content = response.content,
exception = response.exception,
url = this.getLoadUrl();
me.loaded = true;
if ((exception || status === 0) && !_environment.phantom) {
me.error =
//<debug>
("Failed loading synchronously via XHR: '" + url +
"'. It's likely that the file is either being loaded from a " +
"different domain or from the local file system where cross " +
"origin requests are not allowed for security reasons. Try " +
"asynchronous loading instead.") ||
//</debug>
true;
me.evaluated = true;
}
else if ((status >= 200 && status < 300) || status === 304
|| _environment.phantom
|| (status === 0 && content.length > 0)
) {
me.content = content;
}
else {
me.error =
//<debug>
("Failed loading synchronously via XHR: '" + url +
"'. Please verify that the file exists. XHR status code: " +
status) ||
//</debug>
true;
me.evaluated = true;
}
},
Ext create动态加载分析的更多相关文章
- DexClassLoader动态加载分析
转载自:http://www.blogfshare.com/dexclassloader.html 看到原来有把原始的dex文件加密保存,然后解密后使用DexClassLoader加载文件的方法,就来 ...
- ExtJS4.x动态加载js文件
动态加载js文件是ext4.x的一个新特性,可以有效的减少浏览器的压力,提高渲染速度.如动态加载自定义组件 1.在js/extjs/ux目录下,建立自定义组件的js文件. 2.编写MyWindow.j ...
- ExtJs 通过分析源代码解决动态加载Controller的问题
通过分析源代码解决动态加载Controller的问题 最近在研究ExtJs(4.2.0)的MVC开发模式,具体Extjs的MVC如何使用这里不解释,具体参见ExtJs的官方文档.这里要解决的问题是如何 ...
- Ext JS 如何动态加载JavaScript创建窗体
JavaScript不需要编译即可运行,这让JavaScript构建的应用程序可以变得很灵活.我们可以根据需要动态从服务器加载JavaScript脚本来创建和控制UI来与用户交互.下面结合Ext JS ...
- Ext动态加载Toolbar
在使用Ext的GridPanel时候,有时候需要面板不用重新加载而去更新Store或者Toolbar,Store的方法有很多,例如官方api给我们提供的Store.load(),Store.reLoa ...
- 动态加载框架DL分析
动态加载框架DL分析 插件化开发,主要解决三个问题1.动态加载未安装的apk,dex,jar等文件2.activity生命周期的问题,还有service3.Android的资源调用的问题 简单说一下怎 ...
- Ext JS学习第十天 Ext基础之动态加载JS文件(补充)
此文用来记录学习笔记: •Ext4.x版本提供的一大亮点就是Ext.Loader这个类的动态加载机制!只要遵循路径规范,即可动态加载js文件,方便把自己扩展组件动态加载进来,并且减轻浏览器的压力. • ...
- Extjs-树 Ext.tree.TreePanel 动态加载数据
先上效果图 1.说明Ext.tree.Panel 控件是树形控件,大家知道树形结构在软件开发过程中的应用是很广泛的,树形控件的数据有本地数据.服务器端返回的数据两种.对于本地数据的加载,在extjs的 ...
- Ext选项卡tabpanel切换动态加载数据
鸣人不说暗话,来张图: 代码开始:(使用Ext,ajax加载数据,如果你们有好的方法也可以多多交流)var tabxsk = new Object(); //初始化 tabxsk.init = fun ...
随机推荐
- C - Building Fence
Long long ago, there is a famous farmer named John. He owns a big farm and many cows. There are two ...
- thinkphp中setInc、setDec方法
可用于统计字段(通常是数字类型的字段)的更新,例如积分,等级,登陆次数等 必须配合连贯操作where一起使用 score 是数据库指定的某个字段 $User = M("User" ...
- linux下安装cmake(安装opencv库)
apt-get install cmake cmake --version(显示版本号) cmake-gui(打开gui界面) 如果打不该GUI界面时候就需要apt-get install cmake ...
- c语言笔记 数组2
15. c99以前一直使用 gets 和 puts来输入输出字符串,但是gets因为无法获知内存大小,容易出现内存溢出(对此c99对gets,采取保留态势,c11直接废除,但是某些编译器仍然默认可以使 ...
- [No0000115]打开Excel2016提示内存或磁盘空间不足的解决方法
症状: 法一:右键文件,并 解除锁定: 法二: 在系统的服务中查看Windows Firewall服务 和Windows Update服务是否开启,如果没有开启就把他们启动一下. 1.在桌面的[计算机 ...
- 为什么实数系里不存在最小正数?(Why the smallest positive real number doesn't exist in the real number system ?)
We define the smallest positive real number as the number which is explicitly greater than zero and ...
- 安装arcgis10.5不能启动服务的解决方案
最近由于公司需要,要装arcgis10.5,但是装这软件就费了好久的功夫.以前用的10.2,安装比较简单,但是10.5看起来就不一样了,下载完成后就会发现多了一个破解文件.按照教程一步一步安装的,但是 ...
- 出于性能考虑,C语言自动地以传地址的方式将数组传递给被调函数 const 编译错误 最小权限原则
#include <stdio.h> int main(void) { char array[5]; printf("array=%p,&array[0]=%p,& ...
- mongodb操作文件
mongodb操作文件,主要是通过GridFS类.存储文件主要存放在fs中,其中的fs是数据库默认的.并且GridFS是直接与数据库打交道,与collection集合无关. ============= ...
- python之类中如何判断是函数还是方法
通常我们认为在类中的函数为方法,类外面声明def为函数,这种说法有点片面 方法1: class Work(object): def show(self): print("执行show方法&q ...