Skip to content

Commit

Permalink
fix:customDeferredGetConf (#940)
Browse files Browse the repository at this point in the history
* fix:customDeferredGetConf

* version patch

* style update
  • Loading branch information
dongshihao authored and xuexb committed Nov 29, 2017
1 parent 8542388 commit 59b47a2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/mip-custom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,26 @@ define(function (require) {
});
}


/**
* [getConfigScriptElement 获取页面配置的content内容]
* 不在此做解析
*
* @param {HTMLElement} elem mip-custom element 节点
* @return {HTMLScriptElement} 返回`application/json`的script配置节点
*/
function getConfigScriptElement(elem) {
if (!elem) {
return;
}
return elem.querySelector('script[type="application/json"]');
}


return {
render: render,
proxyLink: proxyLink
proxyLink: proxyLink,
getConfigScriptElement: getConfigScriptElement
};

});
21 changes: 20 additions & 1 deletion src/mip-custom/mip-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,30 @@ define(function () {
};

/**
* build钩子, 定制化渲染的主流程:分区请求+渲染
* build钩子,触发渲染
*
*/
customElement.prototype.build = function () {
var me = this;
var checkElement = function () {
if (dom.getConfigScriptElement(me.element)) {
me.initCustom();
return true;
}
return false;
};

if (!checkElement()) {
window.requestAnimationFrame(checkElement);
}
};

/**
* 定制化渲染的主流程:分区请求+渲染
*
*/
customElement.prototype.initCustom = function () {
var me = this;

// 初始化
me.initBuild();
Expand Down
2 changes: 1 addition & 1 deletion src/mip-custom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mip-custom",
"version": "1.2.0",
"version": "1.2.1",
"description": "定制化MIP加载器组件",
"contributors": [
{
Expand Down
4 changes: 2 additions & 2 deletions src/mip-custom/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define(function (require) {
* @type {Object}
*/
var util = require('util');

var dom = require('mip-custom/dom');
var data = require('mip-custom/data');

/**
Expand Down Expand Up @@ -41,7 +41,7 @@ define(function (require) {

// 获取用户设置参数,获取不到则报错并返回
try {
var script = element.querySelector('script[type="application/json"]');
var script = dom.getConfigScriptElement(element);
if (script) {
userParams = JSON.parse(script.textContent);
if (!userParams.accid) {
Expand Down

0 comments on commit 59b47a2

Please sign in to comment.