Browse Source

生命周期可以通过属性传递操作

master
guy 4 years ago
parent
commit
bded9b2b00
  1. 1
      changelog.md
  2. 2
      src/core/__test__/context.test.js
  3. 38
      src/core/__test__/widget.test.js
  4. 12
      src/core/widget.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志
2.0(2020-11)
- 生命周期可以通过属性传递来操作
- 修复了颜色选择器hex框不能输入为空的问题
- 增加纯文本组件bi.pure_text
- store支持webworker,引入多线程机制

2
src/core/__test__/context.test.js

@ -1,5 +1,5 @@
/**
* Created by windy on 2018/01/23.
* Created by guy on 2018/01/23.
*/
describe("contextTest", function () {

38
src/core/__test__/widget.test.js

@ -0,0 +1,38 @@
/**
* Created by guy on 2018/01/23.
*/
describe("widgetTest", function () {
before(function () {
});
/**
* test_author_guy
*/
it("widget生命周期测试", function () {
var Demo = BI.inherit(BI.Widget, {
render: function () {
return {
type: "bi.label",
text: "old"
};
}
});
BI.shortcut("demo.demo", Demo);
var demo = BI.Test.createWidget({
type: "demo.demo",
render: function () {
return {
type: "bi.label",
text: "new"
};
}
});
expect(demo.element.text()).to.equal("new");
demo.destroy();
});
});

12
src/core/widget.js

@ -8,8 +8,9 @@
!(function () {
function callLifeHook (self, life) {
if (self[life]) {
var hooks = BI.isArray(self[life]) ? self[life] : [self[life]];
var hook = self.options[life] || self[life];
if (hook) {
var hooks = BI.isArray(hook) ? hook : [hook];
BI.each(hooks, function (i, hook) {
hook.call(self);
});
@ -84,9 +85,9 @@
},
_initRender: function () {
if (this.beforeInit) {
if (this.options.beforeInit || this.beforeInit) {
this.__asking = true;
this.beforeInit(BI.bind(this._render, this));
(this.options.beforeInit || this.beforeInit)(BI.bind(this._render, this));
if (this.__asking === true) {
this.__async = true;
}
@ -184,7 +185,8 @@
_initElement: function () {
var self = this;
var els = this.render && this.render();
var render = this.options.render || this.render;
var els = render && render.call(this);
if (BI.isPlainObject(els)) {
els = [els];
}

Loading…
Cancel
Save