Browse Source

Pull request #3144: KERNEL-13158: 优化下useContext

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

* commit '5ed8b8e2eeca38b1b43d9dbbf2ac55383b559c47':
  KERNEL-13158: 优化下useContext
  KERNEL-13158: 优化下useContext
es6
guy-王川 2 years ago
parent
commit
73361e8ef7
  1. 4
      dist/fix/fix.compact.js
  2. 16
      examples/useContext.html
  3. 7
      src/core/4.widget.js

4
dist/fix/fix.compact.js vendored

@ -78,7 +78,7 @@
}, options); }, options);
}; };
function findStore (widget) { BI.Widget.findStore = function findStore (widget) {
if (target != null) { if (target != null) {
return target; return target;
} }
@ -110,7 +110,7 @@
return true; return true;
} }
if (this._store) { if (this._store) {
var store = findStore(this.options.context || this._parent || this.options.element || this._context); var store = BI.Widget.findStore(this.options.context || this._parent || this.options.element || this._context);
if (store) { if (store) {
pushTarget(store); pushTarget(store);
needPop = true; needPop = true;

16
examples/useContext.html

@ -5,11 +5,13 @@
<!-- <link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.min.css"/> <!-- <link rel="stylesheet" type="text/css" href="../dist/2.0/fineui.min.css"/>
<script src="../dist/2.0/fineui.js"></script> --> <script src="../dist/2.0/fineui.js"></script> -->
<link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/> <link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css"/>
<script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script> <script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script>
<!-- <script src="http://localhost:9001/fineui.js"></script>-->
</head> </head>
<style> <style>
.my-parent { .my-parent {
--css-scale: 1; --css-scale: 1;
font-size: calc(var(--css-scale) * 14px);
} }
</style> </style>
<body> <body>
@ -98,6 +100,18 @@
ref: function (_ref) { ref: function (_ref) {
child = _ref; child = _ref;
} }
}, {
type: "bi.dynamic_date_combo",
supportDynamic: false,
width: 200,
value: {
type: 1,
value: {
year: 2012,
month: 3,
day: 15
}
}
}] }]
}; };
}; };

7
src/core/4.widget.js

@ -902,8 +902,9 @@
}; };
BI.useContext = function (inject) { BI.useContext = function (inject) {
if (BI.Model.target) { // 通过组件找最近的store
var vm = BI.Model.target; var vm = BI.Widget.findStore(BI.Widget.current);
if (vm) {
if (inject) { if (inject) {
if (vm.$$computed && inject in vm.$$computed) { if (vm.$$computed && inject in vm.$$computed) {
return vm; return vm;
@ -923,7 +924,7 @@
return null; return null;
} }
} }
return BI.Model.target; return vm;
}; };
BI.watch = function (vm, watch, handler) { BI.watch = function (vm, watch, handler) {

Loading…
Cancel
Save