From 532543395a63ebda0c189ee42b459fa4daeb1cc9 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:22:42 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/useContext.html | 94 ++++++++++++++++++++++++++++++++++++++++ src/core/4.widget.js | 36 +++++++++++++-- 2 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 examples/useContext.html diff --git a/examples/useContext.html b/examples/useContext.html new file mode 100644 index 000000000..8762ba34c --- /dev/null +++ b/examples/useContext.html @@ -0,0 +1,94 @@ + + + + + + + + + +
+ + + diff --git a/src/core/4.widget.js b/src/core/4.widget.js index c104a03c5..fcd71aab3 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -768,10 +768,40 @@ } }; - BI.watch = function (watch, handler) { + BI.useContext = function () { + return BI.Model.target; + }; + + BI.watch = function (vm, watch, handler, options) { if (BI.Widget.current) { - BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); - BI.Widget.current.$watchDelayCallbacks.push([watch, handler]); + options = options || {}; + if (vm instanceof BI.Model) { + BI.Widget.current._watchers || (BI.Widget.current._watchers = []); + if (BI.isKey(watch)) { + var k = watch; + watch = {}; + watch[k] = handler; + } + for (var key in watch) { + var handler = watch[key]; + if (BI.isArray(handler)) { + for (var i = 0; i < handler.length; i++) { + BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, BI.extend(options, { + store: vm.store + }))); + } + } else { + BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, BI.extend(options, { + store: vm.store + }))); + } + } + } else { + handler = watch; + watch = vm; + BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); + BI.Widget.current.$watchDelayCallbacks.push([watch, handler]); + } } }; From b9bdc625aacb90f03edfd578448bb59513e627ab Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:25:18 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/4.widget.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index fcd71aab3..7fc406f3e 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -772,7 +772,7 @@ return BI.Model.target; }; - BI.watch = function (vm, watch, handler, options) { + BI.watch = function (vm, watch, handler) { if (BI.Widget.current) { options = options || {}; if (vm instanceof BI.Model) { @@ -786,14 +786,14 @@ var handler = watch[key]; if (BI.isArray(handler)) { for (var i = 0; i < handler.length; i++) { - BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, BI.extend(options, { - store: vm.store - }))); + BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, { + store: vm + })); } } else { - BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, BI.extend(options, { - store: vm.store - }))); + BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, { + store: vm + })); } } } else { From af50f2bbc446c6c74e2ff4daceee1ae7738c6b57 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:25:48 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 38b9c7fcd..3c1fc91be 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2021-12) +- 支持BI.useContext获取上下文环境 - BI.Msg.alert支持message传json格式 - 支持BI.config(function(){})进行系统配置 From 1b1465d05cf4df65f7867a49222cd6026f090924 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:28:14 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/4.widget.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 7fc406f3e..3795e8b68 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -774,7 +774,6 @@ BI.watch = function (vm, watch, handler) { if (BI.Widget.current) { - options = options || {}; if (vm instanceof BI.Model) { BI.Widget.current._watchers || (BI.Widget.current._watchers = []); if (BI.isKey(watch)) { From 45a9352c427b02836600e89c79df18dd959eadb1 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:36:05 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/4.widget.js | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 3795e8b68..34d541285 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -773,34 +773,40 @@ }; BI.watch = function (vm, watch, handler) { - if (BI.Widget.current) { - if (vm instanceof BI.Model) { - BI.Widget.current._watchers || (BI.Widget.current._watchers = []); - if (BI.isKey(watch)) { - var k = watch; - watch = {}; - watch[k] = handler; - } - for (var key in watch) { - var handler = watch[key]; - if (BI.isArray(handler)) { - for (var i = 0; i < handler.length; i++) { - BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, { - store: vm - })); - } - } else { - BI.Widget.current._watchers.push(Fix.watch(vm.model, key, handler, { + if (vm instanceof BI.Model) { + var watchers = []; + if (BI.isKey(watch)) { + var k = watch; + watch = {}; + watch[k] = handler; + } + for (var key in watch) { + var innerHandler = watch[key]; + if (BI.isArray(handler)) { + for (var i = 0; i < handler.length; i++) { + watchers.push(Fix.watch(vm.model, key, innerHandler, { store: vm })); } + } else { + watchers.push(Fix.watch(vm.model, key, innerHandler, { + store: vm + })); } - } else { - handler = watch; - watch = vm; - BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); - BI.Widget.current.$watchDelayCallbacks.push([watch, handler]); } + if (vm._widget) { + vm._widget._watchers || (vm._widget._watchers = []); + vm._widget._watchers = vm._widget._watchers.concat(watchers); + } + return; + } + if (BI.Widget.current) { + + handler = watch; + watch = vm; + BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); + BI.Widget.current.$watchDelayCallbacks.push([watch, handler]); + } }; From b513d358714a9f23a8f757fcebe31b079f38eb67 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:38:50 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/4.widget.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 34d541285..f8fe45929 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -794,19 +794,16 @@ })); } } - if (vm._widget) { - vm._widget._watchers || (vm._widget._watchers = []); - vm._widget._watchers = vm._widget._watchers.concat(watchers); - } + // vm中一定有_widget + vm._widget._watchers || (vm._widget._watchers = []); + vm._widget._watchers = vm._widget._watchers.concat(watchers); return; } if (BI.Widget.current) { - handler = watch; watch = vm; BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); BI.Widget.current.$watchDelayCallbacks.push([watch, handler]); - } }; From 2454872af0ef1eb5c87ee6cc9da5b79732b425ad Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:44:30 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/useContext.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/useContext.html b/examples/useContext.html index 8762ba34c..2c23788cf 100644 --- a/examples/useContext.html +++ b/examples/useContext.html @@ -40,14 +40,17 @@ setInterval(function () { context.toggle(); }, 1000); - BI.watch(context, "expand", function () { - label.setText(context.model.text); - }); + // BI.watch(context, "expand", function () { + // label.setText(context.model.text); + // }); return { type: "bi.label", ref: function (_ref) { label = _ref; }, + effect: function (w) { + w.setText(context.model.text) + }, text: function () { return context.model.text; } From 277a93ed971a312532d303a1de54e23668e81216 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:45:37 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E6=94=AF=E6=8C=81BI.useContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/dev.html | 500 +++++++-------------------------------- examples/useContext.html | 2 +- 2 files changed, 90 insertions(+), 412 deletions(-) diff --git a/examples/dev.html b/examples/dev.html index 17bfd951b..167c18ac5 100644 --- a/examples/dev.html +++ b/examples/dev.html @@ -1,419 +1,97 @@ - - - - - PullRequest | Code Review as a Service - - - - + + + + + + + +
+ - + setup: function () { + var child; + var store = BI.useStore(); + return function () { + return { + type: "bi.vertical", + vgap: 20, + items: [{ + type: "demo.child", + ref: function (_ref) { + child = _ref; + } + }] + }; + }; + } + }); + BI.shortcut("demo.parent", Widget); + BI.createWidget({ + type: "bi.absolute", + items: [{ + el: { + type: "demo.parent" + }, + top: 100, + left: 100 + }], + element: "#wrapper" + }); + + diff --git a/examples/useContext.html b/examples/useContext.html index 2c23788cf..56c78b2ce 100644 --- a/examples/useContext.html +++ b/examples/useContext.html @@ -49,7 +49,7 @@ label = _ref; }, effect: function (w) { - w.setText(context.model.text) + w.setText(context.model.text); }, text: function () { return context.model.text;