Browse Source

Pull request #2331: 无JIAR任务 支持BI.useContext

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '35dbe38b52096651c85c474d7fa0e5b68e05b020':
  childContext替换成provide
  支持BI.useContext
  支持BI.useContext
es6
guy 3 years ago
parent
commit
86f1b2bbe1
  1. 1
      changelog.md
  2. 3
      dist/fix/fix.js
  3. 20
      src/core/4.widget.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志 # 更新日志
2.0(2021-12) 2.0(2021-12)
- childContext废弃,替换成provide
- 支持BI.useContext获取上下文环境 - 支持BI.useContext获取上下文环境
- BI.Msg.alert支持message传json格式 - BI.Msg.alert支持message传json格式
- 支持BI.config(function(){})进行系统配置 - 支持BI.config(function(){})进行系统配置

3
dist/fix/fix.js vendored

@ -1420,12 +1420,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var context = this.context; var context = this.context;
var inject = this.inject; var inject = this.inject;
var childContext = this.childContext; var childContext = this.childContext;
var provide = this.provide;
var watch$$1 = this.watch; var watch$$1 = this.watch;
var actions = this.actions; var actions = this.actions;
var keys = _.keys(this.$$model).concat(_.keys(state)).concat(_.keys(computed)).concat(inject || []).concat(context || []); var keys = _.keys(this.$$model).concat(_.keys(state)).concat(_.keys(computed)).concat(inject || []).concat(context || []);
var mixins = this.mixins; var mixins = this.mixins;
defineProps(this, keys); defineProps(this, keys);
// deprecated
childContext && defineContext(this, childContext); childContext && defineContext(this, childContext);
provide && defineContext(this, provide);
this.$$model && (this.model.__ob__ = this.$$model.__ob__); this.$$model && (this.model.__ob__ = this.$$model.__ob__);
initMixins(this, mixins); initMixins(this, mixins);
this.init(); this.init();

20
src/core/4.widget.js

@ -768,11 +768,24 @@
} }
}; };
BI.useContext = function () { BI.useContext = function (inject) {
if (BI.Model.target) {
var p = BI.Model.target;
if (inject) {
while (p) {
if (p.$$context && inject in p.$$context) {
return p;
}
p = p._parent;
}
}
}
return BI.Model.target; return BI.Model.target;
}; };
BI.watch = function (vm, watch, handler) { BI.watch = function (vm, watch, handler) {
// 必须要保证组件当前环境存在
if (BI.Widget.current) {
if (vm instanceof BI.Model) { if (vm instanceof BI.Model) {
var watchers = []; var watchers = [];
if (BI.isKey(watch)) { if (BI.isKey(watch)) {
@ -795,11 +808,10 @@
} }
} }
// vm中一定有_widget // vm中一定有_widget
vm._widget._watchers || (vm._widget._watchers = []); BI.Widget.current._watchers || (BI.Widget.current._watchers = []);
vm._widget._watchers = vm._widget._watchers.concat(watchers); BI.Widget.current._watchers = BI.Widget.current._watchers.concat(watchers);
return; 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