Browse Source

支持BI.useContext

es6
guy 3 years ago
parent
commit
a9a19943e8
  1. 43
      src/core/4.widget.js

43
src/core/4.widget.js

@ -784,33 +784,34 @@
}; };
BI.watch = function (vm, watch, handler) { BI.watch = function (vm, watch, handler) {
if (vm instanceof BI.Model) { // 必须要保证组件当前环境存在
var watchers = []; if (BI.Widget.current) {
if (BI.isKey(watch)) { if (vm instanceof BI.Model) {
var k = watch; var watchers = [];
watch = {}; if (BI.isKey(watch)) {
watch[k] = handler; var k = watch;
} watch = {};
for (var key in watch) { watch[k] = handler;
var innerHandler = watch[key]; }
if (BI.isArray(handler)) { for (var key in watch) {
for (var i = 0; i < handler.length; i++) { 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, { watchers.push(Fix.watch(vm.model, key, innerHandler, {
store: vm store: vm
})); }));
} }
} else {
watchers.push(Fix.watch(vm.model, key, innerHandler, {
store: vm
}));
} }
// vm中一定有_widget
BI.Widget.current._watchers || (BI.Widget.current._watchers = []);
BI.Widget.current._watchers = BI.Widget.current._watchers.concat(watchers);
return;
} }
// vm中一定有_widget
vm._widget._watchers || (vm._widget._watchers = []);
vm._widget._watchers = vm._widget._watchers.concat(watchers);
return;
}
if (BI.Widget.current) {
handler = watch; handler = watch;
watch = vm; watch = vm;
BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []); BI.Widget.current.$watchDelayCallbacks || (BI.Widget.current.$watchDelayCallbacks = []);

Loading…
Cancel
Save