Browse Source

Merge pull request #1022 in VISUAL/fineui from ~TELLER/fineui:KERNEL-859 to master

* commit '09fed9a3a39681ef02977a6b3aa2edd7d2bb83a3':
  refactor: 美化代码
  fix: 兼容context的问题
  KERNEL-859 refactor: 改widget生命周期
master
guy 5 years ago
parent
commit
a56b6509c6
  1. 22
      src/core/ob.js
  2. 13
      src/core/shortcut.js
  3. 3
      src/core/widget.js

22
src/core/ob.js

@ -29,23 +29,31 @@
* @abstract
*/
BI.OB = function (config) {
var props = this.props;
if (BI.isFunction(this.props)) {
props = this.props(config);
}
this.options = extend(this._defaultConfig(config), props, config);
this._init();
this._initRef();
this._constructor(config);
};
_.extend(BI.OB.prototype, {
props: {},
init: null,
destroyed: null,
_constructor: function (config) {
this._initProps(config);
this._init();
this._initRef();
},
_defaultConfig: function (config) {
return {};
},
_initProps: function (config) {
var props = this.props;
if (BI.isFunction(this.props)) {
props = this.props(config);
}
this.options = extend(this._defaultConfig(config), props, config);
},
_init: function () {
this._initListeners();
this.init && this.init();

13
src/core/shortcut.js

@ -9,12 +9,15 @@
// 根据配置属性生成widget
var createWidget = function (config) {
if (config["classType"]) {
return new (new Function("return " + config["classType"] + ";")())(config);
}
var cls = kv[config.type];
return new cls(config);
var widget = new cls();
widget._initProps(config);
widget._init();
widget._initRef();
return widget;
};
BI.createWidget = function (item, options, context) {

3
src/core/widget.js

@ -25,6 +25,9 @@
});
},
// 覆盖父类的_constructor方法,widget不走ob的生命周期
_constructor: function () {},
beforeInit: null,
// 生命周期函数

Loading…
Cancel
Save