Browse Source

KERNEL-859 refactor: 改widget生命周期

es6
iapyang 5 years ago
parent
commit
9cc418cd3d
  1. 19
      src/core/ob.js
  2. 12
      src/core/shortcut.js
  3. 3
      src/core/widget.js

19
src/core/ob.js

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

12
src/core/shortcut.js

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

3
src/core/widget.js

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

Loading…
Cancel
Save