guy 7 years ago
parent
commit
d8bb076216
  1. 57
      dist/fix/fix.js

57
dist/fix/fix.js vendored

@ -244,7 +244,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
break; break;
} }
var result = original.apply(this, args); var result = original.apply(this, args);
ob.dep.notify(); notify(ob.parent, ob.parentKey, ob.dep);
return result; return result;
}; };
}); });
@ -452,30 +452,32 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return ob; return ob;
} }
function notify(model, key, dep) { function notify(observer, key, dep) {
dep.notify(); dep.notify();
//触发a.*绑定的依赖 if (observer) {
_.each(model.__ob__._deps, function (dep) { //触发a.*绑定的依赖
dep.notify(); _.each(observer._deps, function (dep) {
});
//触发a.**绑定的依赖
var parent = model.__ob__,
root = model.__ob__,
route = key;
while (parent) {
_.each(parent._scopeDeps, function (dep) {
dep.notify(); dep.notify();
}); });
if (parent.parentKey != null) { //触发a.**绑定的依赖
route = parent.parentKey + '.' + route; var parent = observer,
root = observer,
route = key || "";
while (parent) {
_.each(parent._scopeDeps, function (dep) {
dep.notify();
});
if (parent.parentKey != null) {
route = parent.parentKey + '.' + route;
}
root = parent;
parent = parent.parent;
} }
root = parent; for (var _key2 in root._globalDeps) {
parent = parent.parent; var reg = new RegExp(_key2);
} if (reg.test(route)) {
for (var _key2 in root._globalDeps) { root._globalDeps[_key2].notify();
var reg = new RegExp(_key2); }
if (reg.test(route)) {
root._globalDeps[_key2].notify();
} }
} }
} }
@ -561,7 +563,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
val = newVal; val = newVal;
childOb = !shallow && observe(newVal, observer, key); childOb = !shallow && observe(newVal, observer, key);
obj[key] = childOb ? childOb.model : newVal; obj[key] = childOb ? childOb.model : newVal;
notify(model, key, dep); notify(model.__ob__, key, dep);
} }
}; };
}); });
@ -590,7 +592,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
ob.value[key] = val; ob.value[key] = val;
target = defineReactive(ob.value, ob); target = defineReactive(ob.value, ob);
ob.dep.notify(); notify(ob, key, ob.dep);
return target; return target;
} }
@ -612,7 +614,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
delete ob.value[key]; delete ob.value[key];
target = defineReactive(ob.value, ob); target = defineReactive(ob.value, ob);
ob.dep.notify(); notify(ob, key, ob.dep);
return target; return target;
} }
@ -956,7 +958,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return; return;
} }
//a.**或a.*形式 //a.**或a.*形式
if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp)) { if (/^[1-9a-zA-Z.]+(\*\*$|\*$)/.test(exp) || exp === "**") {
var isGlobal = /\*\*$/.test(exp); var isGlobal = /\*\*$/.test(exp);
if (isGlobal) { if (isGlobal) {
//a.**的形式 //a.**的形式
@ -965,7 +967,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
//a.*的形式 //a.*的形式
exp = exp.replace(".*", ""); exp = exp.replace(".*", "");
} }
var getter = parsePath(exp); var getter = exp === "**" ? function (m) {
return m;
} : parsePath(exp);
var v = getter.call(model, model); var v = getter.call(model, model);
var dep = new Dep(); var dep = new Dep();
if (isGlobal) { if (isGlobal) {
@ -1319,6 +1323,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
exports.observerState = observerState; exports.observerState = observerState;
exports.Observer = Observer; exports.Observer = Observer;
exports.observe = observe; exports.observe = observe;
exports.notify = notify;
exports.defineReactive = defineReactive; exports.defineReactive = defineReactive;
exports.set = set; exports.set = set;
exports.del = del; exports.del = del;

Loading…
Cancel
Save