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 ...
随机推荐
- nodejs yarn包管理工具
Yarn https://yarnpkg.com/zh-Hans/docs/install#windows-stable 安装包 Yarn Npm yarn npm i yarn global add ...
- cuteftp9破解及安装、使用
一.破解: 参考:https://jingyan.baidu.com/article/ca00d56c4e43b2e99febcf70.html 1. 首先下载cuteftp替换文件及cuteftp9 ...
- Maven知识点积累二
①maven常用命令: mvn clean:清除target下编译生成的class文件 mvn compile:编译 mvn package:打包放到target下 mvn install:打包并放到 ...
- Google、微软、Linkedln、Uber、亚马逊等15+海外技术专家聚首2018TOP100Summit
11月30日-12月3日,由msup主办的第七届全球软件案例研究峰会(以下简称为TOP100Summit)将在北京国家会议中心举办.本届峰会以“释放AI生产力,让组织向智能化演进”作为开幕式主题, 4 ...
- [No0000117]visual studio 调试WebForm 显示 HTTP Error 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容。
调试界面如下: 解决办法1:右键设置起始页. 影响文件: 解决方案2:Web.config中添加默认页面配置: <system.webServer> <defaultDocument ...
- React 60S倒计时
React 60S倒计时 1.设置状态: 2.函数主体: 3.应用: 4..效果图:
- MySQL5.6启动报错The server quit without updating PID file
Mysql启动报错如下: [root@db01 opt]# service mysqld start Starting MySQL.... ERROR! The server quit without ...
- android&sqlsever
http://blog.csdn.net/chaoyu168/article/details/51910601
- 终端:Xcode模拟器上安装.app方法
有的时候,我们可能需要将别人的Xcode运行之后的程序包(xxx.app)安装在自己的模拟器上,如下我将介绍如何通过终端来安装. 实现 获取自己Xcode生成的xxx.app steps 1:在工程d ...
- Master-Worker集群计算demo
Task为要执行的任务实体类: package com.viewhigh.mdop.bi.test; /** * Created by zzq on 2017/5/11. */ public clas ...