Browse Source

生命周期函数支持promise

es6
guy 3 years ago
parent
commit
877f8f1061
  1. 11
      examples/dev.html
  2. 10
      src/core/4.widget.js

11
examples/dev.html

@ -2,7 +2,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title></title> <title></title>
<link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.css"/> <link rel="stylesheet" type="text/css" href="http://localhost:9001/fineui.css"/>
<!-- <script src="../dist/2.0/fineui.js"></script>--> <!-- <script src="../dist/2.0/fineui.js"></script>-->
<script src="http://localhost:9001/fineui.js"></script> <script src="http://localhost:9001/fineui.js"></script>
</head> </head>
@ -24,6 +24,13 @@
height: 200, height: 200,
width: 600 width: 600
}, },
beforeInit: function () {
return new Promise(function (resolve) {
setTimeout(function () {
resolve();
}, 1000);
});
},
_store: function () { _store: function () {
return BI.Models.getModel("demo.model"); return BI.Models.getModel("demo.model");
}, },
@ -49,7 +56,7 @@
type: "bi.button", type: "bi.button",
text: "点击", text: "点击",
handler: function () { handler: function () {
store.model.columnSize = [300, "fill"] store.model.columnSize = [300, "fill"];
} }
}] }]
}] }]

10
src/core/4.widget.js

@ -133,7 +133,10 @@
if (self.options.beforeRender || self.beforeRender) { if (self.options.beforeRender || self.beforeRender) {
self.__async = true; self.__async = true;
(self.options.beforeRender || self.beforeRender).call(self, render); var beforeRenderResult = (self.options.beforeRender || self.beforeRender).call(self, render);
if (beforeRenderResult instanceof Promise) {
beforeRenderResult.then(init);
}
} else { } else {
self._render(); self._render();
self.__afterRender(); self.__afterRender();
@ -142,7 +145,10 @@
if (this.options.beforeInit || this.beforeInit) { if (this.options.beforeInit || this.beforeInit) {
this.__asking = true; this.__asking = true;
(this.options.beforeInit || this.beforeInit).call(this, init); var beforeInitResult = (this.options.beforeInit || this.beforeInit).call(this, init);
if (beforeInitResult instanceof Promise) {
beforeInitResult.then(init);
}
} else { } else {
init(); init();
} }

Loading…
Cancel
Save