Skip to content

Commit 7a082c2

Browse files
Slightly clean up getter function generation
1 parent 9e69eec commit 7a082c2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,24 @@ function getterFn (key, fn) {
100100

101101
let getter = fn.get
102102

103-
if (fn.hasOwnProperty('watch') || fn.hasOwnProperty('shouldUpdate')) {
104-
let shouldUpdate = fn.shouldUpdate || (() => true)
105-
let watcher = fn.watch || (() => {})
103+
if (fn.hasOwnProperty('watch')) {
104+
const previousGetter = getter
106105
getter = function getter () {
107-
watcher.call(this)
108-
if (shouldUpdate.call(this)) {
109-
return fn.get.call(this)
106+
fn.watch.call(this)
107+
return previousGetter.call(this)
108+
}
109+
}
110+
111+
if (fn.hasOwnProperty('shouldUpdate')) {
112+
const previousGetter = getter
113+
getter = function getter () {
114+
if (fn.shouldUpdate.call(this)) {
115+
return previousGetter.call(this)
110116
}
111117
return DidNotUpdate
112118
}
113119
}
120+
114121
if (isComputedLazy(fn)) {
115122
const nonLazy = getter
116123
getter = function lazyGetter () {

0 commit comments

Comments
 (0)