From bded9b2b00b9102ad7d0123b34c25ec9793be442 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 24 Nov 2020 17:45:56 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=9A=E8=BF=87=E5=B1=9E=E6=80=A7=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + src/core/__test__/context.test.js | 2 +- src/core/__test__/widget.test.js | 38 +++++++++++++++++++++++++++++++ src/core/widget.js | 12 ++++++---- 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/core/__test__/widget.test.js diff --git a/changelog.md b/changelog.md index 70356883d..c0e5a4e27 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2020-11) +- 生命周期可以通过属性传递来操作 - 修复了颜色选择器hex框不能输入为空的问题 - 增加纯文本组件bi.pure_text - store支持webworker,引入多线程机制 diff --git a/src/core/__test__/context.test.js b/src/core/__test__/context.test.js index 9dd7414c9..8038fa9eb 100644 --- a/src/core/__test__/context.test.js +++ b/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 () { diff --git a/src/core/__test__/widget.test.js b/src/core/__test__/widget.test.js new file mode 100644 index 000000000..2c3d60183 --- /dev/null +++ b/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(); + }); + +}); diff --git a/src/core/widget.js b/src/core/widget.js index 6d8cb3929..4e9abe7fd 100644 --- a/src/core/widget.js +++ b/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]; } From 6b941b83c950f6d1a90ba354eed98c4a6e607637 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 25 Nov 2020 21:56:09 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/less/base/segment/segment.less | 4 +- src/less/core/utils/common.less | 132 +++++++++++++++-------------- 2 files changed, 72 insertions(+), 64 deletions(-) diff --git a/src/less/base/segment/segment.less b/src/less/base/segment/segment.less index d72dcf8a0..7796d85af 100644 --- a/src/less/base/segment/segment.less +++ b/src/less/base/segment/segment.less @@ -30,7 +30,7 @@ border-bottom: 1px solid @color-bi-border-line-theme-dark; } & > .first-element{ - border-left: 1px solid @color-bi-background-default-theme-dark; + border-left: 1px solid @color-bi-border-line-theme-dark; } } -} \ No newline at end of file +} diff --git a/src/less/core/utils/common.less b/src/less/core/utils/common.less index 58e24bf76..35a3e9dda 100644 --- a/src/less/core/utils/common.less +++ b/src/less/core/utils/common.less @@ -927,35 +927,83 @@ textarea { } } &.disabled { - color: @color-bi-text-disabled !important; - & .bi-input { - color: @color-bi-text-disabled !important; - } - & .bi-textarea { - color: @color-bi-text-disabled !important; - } - background-color: transparent !important; - & .bi-high-light { + &, &:hover, &:active { color: @color-bi-text-disabled !important; - } - &.bi-high-light-border { - border-color: @color-bi-border-disabled; - } - &.hover, &.active { - color: @color-bi-text !important; & .bi-input { - color: @color-bi-text !important; + color: @color-bi-text-disabled !important; } & .bi-textarea { - color: @color-bi-text !important; + color: @color-bi-text-disabled !important; } - background-color: @color-bi-background-dark-gray !important; + background-color: transparent !important; & .bi-high-light { color: @color-bi-text-disabled !important; } &.bi-high-light-border { border-color: @color-bi-border-disabled; } + &.hover, &.active { + color: @color-bi-text !important; + & .bi-input { + color: @color-bi-text !important; + } + & .bi-textarea { + color: @color-bi-text !important; + } + background-color: @color-bi-background-dark-gray !important; + & .bi-high-light { + color: @color-bi-text-disabled !important; + } + &.bi-high-light-border { + border-color: @color-bi-border-disabled; + } + } + } + } +} + +.bi-theme-dark { + .bi-list-item-select { + &:hover, &.hover { + color: @color-bi-text; + & .bi-input { + color: @color-bi-text; + } + & .bi-textarea { + color: @color-bi-text; + } + .background-color(@color-bi-background-default, 5%); + } + &:active, &.active { + color: @color-bi-text; + & .bi-input { + color: @color-bi-text; + } + & .bi-textarea { + color: @color-bi-text; + } + background-color: @color-bi-background-highlight; + & .bi-high-light { + color: @color-bi-text; + } + } + &.disabled { + &, &:hover, &:active { + background-color: transparent !important; + color: @color-bi-text-disabled-theme-dark !important; + & .bi-input { + color: @color-bi-text-disabled-theme-dark !important; + } + & .bi-textarea { + color: @color-bi-text-disabled-theme-dark !important; + } + & .bi-high-light { + color: @color-bi-text-disabled-theme-dark !important; + } + } + &.hover, &.active { + background-color: @background-color-black-theme-dark !important; + } } } } @@ -1031,7 +1079,7 @@ textarea { &.active { background-color: @color-bi-background-default-theme-dark; } - + &.disabled { &, &:hover, &:active { background-color: transparent !important; @@ -1046,6 +1094,9 @@ textarea { color: @color-bi-text-disabled-theme-dark !important; } } + &.active { + background-color: @background-color-black-theme-dark !important; + } } } } @@ -1095,49 +1146,6 @@ textarea { } } -.bi-theme-dark { - .bi-list-item-select { - &:hover, &.hover { - color: @color-bi-text; - & .bi-input { - color: @color-bi-text; - } - & .bi-textarea { - color: @color-bi-text; - } - .background-color(@color-bi-background-default, 5%); - } - &:active, &.active { - color: @color-bi-text; - & .bi-input { - color: @color-bi-text; - } - & .bi-textarea { - color: @color-bi-text; - } - background-color: @color-bi-background-highlight; - & .bi-high-light { - color: @color-bi-text; - } - } - &.disabled { - &, &:hover, &:active { - background-color: transparent !important; - color: @color-bi-text-disabled-theme-dark !important; - & .bi-input { - color: @color-bi-text-disabled-theme-dark !important; - } - & .bi-textarea { - color: @color-bi-text-disabled-theme-dark !important; - } - & .bi-high-light { - color: @color-bi-text-disabled-theme-dark !important; - } - } - } - } -} - //去掉list-item效果 .bi-list-item-none { &:hover, &.hover { From 0d259071f261eea2395dd2cd7331bd2e365d929e Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 25 Nov 2020 21:58:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/widget.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/widget.js b/src/core/widget.js index 4e9abe7fd..6ef2a1079 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -8,9 +8,8 @@ !(function () { function callLifeHook (self, life) { - var hook = self.options[life] || self[life]; - if (hook) { - var hooks = BI.isArray(hook) ? hook : [hook]; + if (self[life]) { + var hooks = BI.isArray(self[life]) ? self[life] : [self[life]]; BI.each(hooks, function (i, hook) { hook.call(self); }); @@ -85,9 +84,9 @@ }, _initRender: function () { - if (this.options.beforeInit || this.beforeInit) { + if (this.beforeInit) { this.__asking = true; - (this.options.beforeInit || this.beforeInit)(BI.bind(this._render, this)); + this.beforeInit(BI.bind(this._render, this)); if (this.__asking === true) { this.__async = true; } @@ -185,8 +184,7 @@ _initElement: function () { var self = this; - var render = this.options.render || this.render; - var els = render && render.call(this); + var els = this.render && this.render(); if (BI.isPlainObject(els)) { els = [els]; } @@ -612,6 +610,7 @@ if (o.element) { return BI.$(o.element); } + return BI.$(document.createElement(o.tagName)); if (o.tagName) { return BI.$(document.createElement(o.tagName)); } @@ -660,3 +659,4 @@ return widget._mount(true, false, false, predicate); }; })(); + From ee6f525373f97c6f0557a20f9a9196957f7ab2bd Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 25 Nov 2020 21:59:49 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/widget.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/core/widget.js b/src/core/widget.js index 6ef2a1079..1e76a8ffe 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -611,10 +611,6 @@ return BI.$(o.element); } return BI.$(document.createElement(o.tagName)); - if (o.tagName) { - return BI.$(document.createElement(o.tagName)); - } - return BI.$(document.createDocumentFragment()); } return BI.$(widget); }, From db356a09031bb049829a540748d022b635d63900 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 25 Nov 2020 22:01:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/widget.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/widget.js b/src/core/widget.js index 1e76a8ffe..fc6d28957 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -610,7 +610,10 @@ if (o.element) { return BI.$(o.element); } - return BI.$(document.createElement(o.tagName)); + if (o.tagName) { + return BI.$(document.createElement(o.tagName)); + } + return BI.$(document.createDocumentFragment()); } return BI.$(widget); },