Browse Source

Pull request #1539: 无JIRA任务 context重构, 新增inject属性

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

* commit 'bcc2b1fe3bbf681c4fb79c2c37b77497daf9b3fb':
  context重构, 新增inject属性
es6
guy 4 years ago
parent
commit
6638ddb52b
  1. 24
      dist/fix/fix.js

24
dist/fix/fix.js vendored

@ -1332,6 +1332,25 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
vm.$$context = createViewModel$1({}, props); vm.$$context = createViewModel$1({}, props);
} }
function getInjectValue(vm, key) {
var p = vm._parent;
while (p) {
if (p.$$context && key in p.$$context) {
return p.$$context[key];
}
p = p._parent;
}
}
function getInjectValues(vm) {
var inject = vm.inject || [];
var result = {};
_.each(inject, function (key) {
result[key] = getInjectValue(vm, key);
});
return result;
}
var Model = function () { var Model = function () {
function Model() { function Model() {
_classCallCheck(this, Model); _classCallCheck(this, Model);
@ -1350,17 +1369,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var state = _.isFunction(this.state) ? this.state() : this.state; var state = _.isFunction(this.state) ? this.state() : this.state;
var computed = this.computed; var computed = this.computed;
var context = this.context; var context = this.context;
var inject = this.inject;
var childContext = this.childContext; var childContext = this.childContext;
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(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);
childContext && defineContext(this, childContext); childContext && defineContext(this, childContext);
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();
initState(this, state); initState(this, _.extend(getInjectValues(this), state));
initComputed(this, computed); initComputed(this, computed);
initWatch(this, watch$$1); initWatch(this, watch$$1);
initMethods(this, actions); initMethods(this, actions);

Loading…
Cancel
Save