From 45a9352c427b02836600e89c79df18dd959eadb1 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Dec 2021 19:36:05 +0800 Subject: [PATCH] =?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]); + } };