Skip to content

Commit

Permalink
Update watcher.js
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon942 authored Aug 6, 2020
1 parent 6c1f387 commit 19b3c0c
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions src/core/observer/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class Watcher {
this.lazy = !!options.lazy
this.sync = !!options.sync
this.before = options.before
if(options.fixed) this.noRe = false // fixed dependencies, no retracking; false = untracked, true = tracked
} else {
this.deep = this.user = this.lazy = this.sync = false
}
Expand Down Expand Up @@ -89,35 +90,52 @@ export default class Watcher {
vm
)
}
else{
if(expOrFn.indexOf(".") < 0) this.noRe = false // fixed dependency
}
}
if(!this.lazy){
this.value = this.get()
if(this.noRe===false) this.noRe = true
}
this.value = this.lazy
? undefined
: this.get()
}

/**
* Evaluate the getter, and re-collect dependencies.
*/
get () {
pushTarget(this)
let value
const vm = this.vm
try {
value = this.getter.call(vm, vm)
} catch (e) {
if (this.user) {
handleError(e, vm, `getter for watcher "${this.expression}"`)
} else {
throw e
if(this.noRe){
try {
value = this.getter.call(vm, vm)
} catch (e) {
if (this.user) {
handleError(e, vm, `getter for watcher "${this.expression}"`)
} else {
throw e
}
}
} finally {
// "touch" every property so they are all tracked as
// dependencies for deep watching
if (this.deep) {
traverse(value)
}
else{
pushTarget(this)
try {
value = this.getter.call(vm, vm)
} catch (e) {
if (this.user) {
handleError(e, vm, `getter for watcher "${this.expression}"`)
} else {
throw e
}
} finally {
// "touch" every property so they are all tracked as
// dependencies for deep watching
if (this.deep) {
traverse(value)
}
popTarget()
this.cleanupDeps()
}
popTarget()
this.cleanupDeps()
}
return value
}
Expand Down Expand Up @@ -210,6 +228,7 @@ export default class Watcher {
evaluate () {
this.value = this.get()
this.dirty = false
if(this.noRe===false) this.noRe = true // accomodate 1st "lazy" evaluation
}

/**
Expand Down

0 comments on commit 19b3c0c

Please sign in to comment.