Created
November 28, 2021 01:28
-
-
Save sunnyy02/98892c0a5389cf570989f5e14564dc26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(obj, key, { | |
enumerable: true, | |
configurable: true, | |
get: function reactiveGetter () { | |
const value = getter ? getter.call(obj) : val | |
if (Dep.target) { | |
dep.depend() | |
if (childOb) { | |
childOb.dep.depend() | |
if (Array.isArray(value)) { | |
dependArray(value) | |
} | |
} | |
} | |
return value | |
}, | |
set: function reactiveSetter (newVal) { | |
const value = getter ? getter.call(obj) : val | |
/* eslint-disable no-self-compare */ | |
if (newVal === value || (newVal !== newVal && value !== value)) { | |
return | |
} | |
/* eslint-enable no-self-compare */ | |
if (process.env.NODE_ENV !== 'production' && customSetter) { | |
customSetter() | |
} | |
// #7981: for accessor properties without setter | |
if (getter && !setter) return | |
if (setter) { | |
setter.call(obj, newVal) | |
} else { | |
val = newVal | |
} | |
childOb = !shallow && observe(newVal) | |
dep.notify() | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment