|
|
@ -887,21 +887,21 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
} |
|
|
|
} |
|
|
|
return new Function('return ' + expr)(); |
|
|
|
return new Function('return ' + expr)(); |
|
|
|
} |
|
|
|
} |
|
|
|
function watch(vm, expOrFn, cb, options) { |
|
|
|
function watch(model, expOrFn, cb, options) { |
|
|
|
if (isPlainObject(cb)) { |
|
|
|
if (isPlainObject(cb)) { |
|
|
|
options = cb; |
|
|
|
options = cb; |
|
|
|
cb = cb.handler; |
|
|
|
cb = cb.handler; |
|
|
|
} |
|
|
|
} |
|
|
|
if (typeof cb === 'string') { |
|
|
|
if (typeof cb === 'string') { |
|
|
|
cb = vm[cb]; |
|
|
|
cb = model[cb]; |
|
|
|
} |
|
|
|
} |
|
|
|
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 && !/\*/.test(expOrFn)) { |
|
|
|
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(model, expOrFn, cb, options); |
|
|
|
if (options.immediate) { |
|
|
|
if (options.immediate) { |
|
|
|
cb.call(vm, watcher.value); |
|
|
|
cb(watcher.value); |
|
|
|
} |
|
|
|
} |
|
|
|
return function unwatchFn() { |
|
|
|
return function unwatchFn() { |
|
|
|
watcher.teardown(); |
|
|
|
watcher.teardown(); |
|
|
@ -925,17 +925,17 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
exp = exp.replace(".*", ""); |
|
|
|
exp = exp.replace(".*", ""); |
|
|
|
} |
|
|
|
} |
|
|
|
var getter = parsePath(exp); |
|
|
|
var getter = parsePath(exp); |
|
|
|
var v = getter.call(vm.model, vm.model); |
|
|
|
var v = getter.call(model, model); |
|
|
|
var dep = new Dep(); |
|
|
|
var dep = new Dep(); |
|
|
|
if (isGlobal) { |
|
|
|
if (isGlobal) { |
|
|
|
(v.__ob__._globalDeps || (v.__ob__._globalDeps = [])).push(dep); |
|
|
|
(v.__ob__._globalDeps || (v.__ob__._globalDeps = [])).push(dep); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
(v.__ob__._deps || (v.__ob__._deps = [])).push(dep); |
|
|
|
(v.__ob__._deps || (v.__ob__._deps = [])).push(dep); |
|
|
|
} |
|
|
|
} |
|
|
|
var w = new Watcher(vm.model, function () { |
|
|
|
var w = new Watcher(model, function () { |
|
|
|
dep.depend(); |
|
|
|
dep.depend(); |
|
|
|
return NaN; |
|
|
|
return NaN; |
|
|
|
}, _.bind(cb, vm)); |
|
|
|
}, cb); |
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
watchers.push(function unwatchFn() { |
|
|
|
w.teardown(); |
|
|
|
w.teardown(); |
|
|
|
v.__ob__._globalDeps && remove(v.__ob__._globalDeps, dep); |
|
|
|
v.__ob__._globalDeps && remove(v.__ob__._globalDeps, dep); |
|
|
@ -943,14 +943,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons |
|
|
|
}); |
|
|
|
}); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var watcher = new Watcher(vm.model, exp, function () { |
|
|
|
var watcher = new Watcher(model, exp, function () { |
|
|
|
if (complete === true) { |
|
|
|
if (complete === true) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
fns[i] = true; |
|
|
|
fns[i] = true; |
|
|
|
if (runBinaryFunction(fns)) { |
|
|
|
if (runBinaryFunction(fns)) { |
|
|
|
complete = true; |
|
|
|
complete = true; |
|
|
|
cb.call(vm); |
|
|
|
cb(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!running) { |
|
|
|
if (!running) { |
|
|
|
running = true; |
|
|
|
running = true; |
|
|
|