* A watcher parses an expression, collects dependencies, * and fires callback when the expression value changes. * This is used for both the $watch() api and directives. * * @param {Vue} vm * @param {String|Function} expOrFn * @param {Function} cb * @param {Object} options *
(vm, expOrFn, cb, options)
| 3133 | * @constructor |
| 3134 | */ |
| 3135 | function Watcher(vm, expOrFn, cb, options) { |
| 3136 | // mix in options |
| 3137 | if (options) { |
| 3138 | extend(this, options); |
| 3139 | } |
| 3140 | var isFn = typeof expOrFn === 'function'; |
| 3141 | this.vm = vm; |
| 3142 | vm._watchers.push(this); |
| 3143 | this.expression = expOrFn; |
| 3144 | this.cb = cb; |
| 3145 | this.id = ++uid$2; // uid for batching |
| 3146 | this.active = true; |
| 3147 | this.dirty = this.lazy; // for lazy watchers |
| 3148 | this.deps = []; |
| 3149 | this.newDeps = []; |
| 3150 | this.depIds = new _Set(); |
| 3151 | this.newDepIds = new _Set(); |
| 3152 | this.prevError = null; // for async error stacks |
| 3153 | // parse expression for getter/setter |
| 3154 | if (isFn) { |
| 3155 | this.getter = expOrFn; |
| 3156 | this.setter = undefined; |
| 3157 | } else { |
| 3158 | var res = parseExpression(expOrFn, this.twoWay); |
| 3159 | this.getter = res.get; |
| 3160 | this.setter = res.set; |
| 3161 | } |
| 3162 | this.value = this.lazy ? undefined : this.get(); |
| 3163 | // state for avoiding false triggers for deep and Array |
| 3164 | // watchers during vm._digest() |
| 3165 | this.queued = this.shallow = false; |
| 3166 | } |
| 3167 | |
| 3168 | /** |
| 3169 | * Evaluate the getter, and re-collect dependencies. |
nothing calls this directly
no test coverage detected