|
|
@ -395,12 +395,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Observer.prototype.walk = function walk(obj) { |
|
|
|
Observer.prototype.walk = function walk(obj) { |
|
|
|
return defineReactive(obj); |
|
|
|
return defineReactive(obj, this); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Observer.prototype.observeArray = function observeArray(items) { |
|
|
|
Observer.prototype.observeArray = function observeArray(items) { |
|
|
|
for (var i = 0, l = items.length; i < l; i++) { |
|
|
|
for (var i = 0, l = items.length; i < l; i++) { |
|
|
|
items[i] = observe(items[i]).model; |
|
|
|
items[i] = observe(items[i], this).model; |
|
|
|
} |
|
|
|
} |
|
|
|
return items; |
|
|
|
return items; |
|
|
|
}; |
|
|
|
}; |
|
|
@ -422,32 +422,30 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function observe(value, asRootData) { |
|
|
|
function observe(value, parentObserver) { |
|
|
|
if (!_.isObject(value)) { |
|
|
|
if (!_.isObject(value)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var ob = void 0; |
|
|
|
var ob = void 0; |
|
|
|
if (_.has(value, '__ob__') && value.__ob__ instanceof Observer) { |
|
|
|
if (_.has(value, '__ob__') && value.__ob__ instanceof Observer) { |
|
|
|
ob = value.__ob__; |
|
|
|
ob = value.__ob__; |
|
|
|
} else if (observerState.shouldConvert && (_.isArray(value) || isPlainObject(value)) && !value._isVue) { |
|
|
|
} else if (observerState.shouldConvert && (_.isArray(value) || isPlainObject(value))) { |
|
|
|
ob = new Observer(value); |
|
|
|
ob = new Observer(value); |
|
|
|
} |
|
|
|
} |
|
|
|
if (asRootData && ob) { |
|
|
|
ob.parent = parentObserver || ob.parent; |
|
|
|
ob.vmCount++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ob; |
|
|
|
return ob; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function defineReactive(obj, observer, shallow) { |
|
|
|
function defineReactive(obj, observer, shallow) { |
|
|
|
|
|
|
|
|
|
|
|
var props = {}; |
|
|
|
var props = {}; |
|
|
|
|
|
|
|
var model = void 0; |
|
|
|
_.each(obj, function (val, key) { |
|
|
|
_.each(obj, function (val, key) { |
|
|
|
if (key in $$skipArray) { |
|
|
|
if (key in $$skipArray) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var dep = observer && observer['__dep' + key] || new Dep(); |
|
|
|
var dep = observer && observer['__dep' + key] || new Dep(); |
|
|
|
observer && (observer['__dep' + key] = dep); |
|
|
|
observer && (observer['__dep' + key] = dep); |
|
|
|
var childOb = !shallow && observe(val); |
|
|
|
var childOb = !shallow && observe(val, observer); |
|
|
|
props[key] = { |
|
|
|
props[key] = { |
|
|
|
enumerable: true, |
|
|
|
enumerable: true, |
|
|
|
configurable: true, |
|
|
|
configurable: true, |
|
|
@ -470,13 +468,25 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
val = newVal; |
|
|
|
val = newVal; |
|
|
|
childOb = !shallow && observe(newVal); |
|
|
|
childOb = !shallow && observe(newVal, observer); |
|
|
|
obj[key] = childOb ? childOb.model : newVal; |
|
|
|
obj[key] = childOb ? childOb.model : newVal; |
|
|
|
dep.notify(); |
|
|
|
dep.notify(); |
|
|
|
|
|
|
|
//触发a.*绑定的hooks
|
|
|
|
|
|
|
|
_.each(model.__ob__._deps, function (dep) { |
|
|
|
|
|
|
|
dep.notify(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
//触发a.**绑定的hooks
|
|
|
|
|
|
|
|
var parent = model.__ob__; |
|
|
|
|
|
|
|
while (parent) { |
|
|
|
|
|
|
|
_.each(parent._globalDeps, function (dep) { |
|
|
|
|
|
|
|
dep.notify(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
parent = parent.parent; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
return createViewModel$1(obj, props); |
|
|
|
return model = createViewModel$1(obj, props); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -495,9 +505,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
return val; |
|
|
|
return val; |
|
|
|
} |
|
|
|
} |
|
|
|
var ob = target.__ob__; |
|
|
|
var ob = target.__ob__; |
|
|
|
if (target._isVue || ob && ob.vmCount) { |
|
|
|
|
|
|
|
return val; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!ob) { |
|
|
|
if (!ob) { |
|
|
|
target[key] = val; |
|
|
|
target[key] = val; |
|
|
|
return val; |
|
|
|
return val; |
|
|
@ -517,9 +524,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var ob = target.__ob__; |
|
|
|
var ob = target.__ob__; |
|
|
|
if (target._isVue || ob && ob.vmCount) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!_.has(target, key)) { |
|
|
|
if (!_.has(target, key)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -951,7 +955,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
options = options || {}; |
|
|
|
options = options || {}; |
|
|
|
options.user = true; |
|
|
|
options.user = true; |
|
|
|
var exps = void 0; |
|
|
|
var exps = void 0; |
|
|
|
if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1) { |
|
|
|
if (_.isFunction(expOrFn) || !(exps = expOrFn.match(/[a-zA-Z0-9_.*]+|[|][|]|[&][&]|[(]|[)]/g)) || exps.length === 1 && !/\*/.test(expOrFn)) { |
|
|
|
var watcher = new Watcher(vm.model, expOrFn, _.bind(cb, vm), options); |
|
|
|
var watcher = new Watcher(vm.model, expOrFn, _.bind(cb, vm), options); |
|
|
|
if (options.immediate) { |
|
|
|
if (options.immediate) { |
|
|
|
cb.call(vm, watcher.value); |
|
|
|
cb.call(vm, watcher.value); |
|
|
@ -968,6 +972,32 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
if (_.has(operators, exp)) { |
|
|
|
if (_.has(operators, exp)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (/\*\*$|\*$/.test(exp)) { |
|
|
|
|
|
|
|
var isGlobal = /\*\*$/.test(exp); |
|
|
|
|
|
|
|
if (isGlobal) { |
|
|
|
|
|
|
|
//a.**的形式
|
|
|
|
|
|
|
|
exp = exp.replace(".**", ""); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
//a.*的形式
|
|
|
|
|
|
|
|
exp = exp.replace(".*", ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var getter = parsePath(exp); |
|
|
|
|
|
|
|
var v = getter.call(vm.model, vm.model); |
|
|
|
|
|
|
|
var dep = new Dep(); |
|
|
|
|
|
|
|
if (isGlobal) { |
|
|
|
|
|
|
|
(v.__ob__._globalDeps || (v.__ob__._globalDeps = [])).push(dep); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
(v.__ob__._deps || (v.__ob__._deps = [])).push(dep); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var w = new Watcher(vm.model, function () { |
|
|
|
|
|
|
|
dep.depend(); |
|
|
|
|
|
|
|
return NaN; |
|
|
|
|
|
|
|
}, _.bind(cb, vm)); |
|
|
|
|
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
|
|
|
|
w.teardown(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
var watcher = new Watcher(vm.model, exp, function () { |
|
|
|
var watcher = new Watcher(vm.model, exp, function () { |
|
|
|
if (complete === true) { |
|
|
|
if (complete === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
|