Browse Source

Pull request #2283: feature:生命周期函数支持promise

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '877f8f10615f1146cccfa02fec8ae887133cab84':
  生命周期函数支持promise
es6
guy 3 years ago
parent
commit
487e51097a
  1. 11
      examples/dev.html
  2. 10
      src/core/4.widget.js

11
examples/dev.html

@ -2,7 +2,7 @@
<head>
<meta charset="utf-8">
<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="http://localhost:9001/fineui.js"></script>
</head>
@ -24,6 +24,13 @@
height: 200,
width: 600
},
beforeInit: function () {
return new Promise(function (resolve) {
setTimeout(function () {
resolve();
}, 1000);
});
},
_store: function () {
return BI.Models.getModel("demo.model");
},
@ -49,7 +56,7 @@
type: "bi.button",
text: "点击",
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) {
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 {
self._render();
self.__afterRender();
@ -142,7 +145,10 @@
if (this.options.beforeInit || this.beforeInit) {
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 {
init();
}

Loading…
Cancel
Save