@@ -2,7 +2,6 @@ import Dep from './dep'
22import { arrayMethods } from './array'
33import {
44 def ,
5- isObject ,
65 isArray ,
76 isPlainObject ,
87 hasProto ,
@@ -11,6 +10,23 @@ import {
1110
1211const arrayKeys = Object . getOwnPropertyNames ( arrayMethods )
1312
13+ /**
14+ * By default, when a reactive property is set, the new value is
15+ * also converted to become reactive. However in certain cases, e.g.
16+ * v-for scope alias and props, we don't want to force conversion
17+ * because the value may be a nested value under a frozen data structure.
18+ *
19+ * So whenever we want to set a reactive property without forcing
20+ * conversion on the new value, we wrap that call inside this function.
21+ */
22+
23+ let shouldConvert = true
24+ export function withoutConversion ( fn ) {
25+ shouldConvert = false
26+ fn ( )
27+ shouldConvert = true
28+ }
29+
1430/**
1531 * Observer class that are attached to each observed
1632 * object. Once attached, the observer converts target
@@ -154,6 +170,7 @@ export function observe (value, vm) {
154170 ) {
155171 ob = value . __ob__
156172 } else if (
173+ shouldConvert &&
157174 ( isArray ( value ) || isPlainObject ( value ) ) &&
158175 Object . isExtensible ( value ) &&
159176 ! value . _isVue
@@ -172,10 +189,9 @@ export function observe (value, vm) {
172189 * @param {Object } obj
173190 * @param {String } key
174191 * @param {* } val
175- * @param {Boolean } doNotObserve
176192 */
177193
178- export function defineReactive ( obj , key , val , doNotObserve ) {
194+ export function defineReactive ( obj , key , val ) {
179195 var dep = new Dep ( )
180196
181197 var property = Object . getOwnPropertyDescriptor ( obj , key )
@@ -187,13 +203,7 @@ export function defineReactive (obj, key, val, doNotObserve) {
187203 var getter = property && property . get
188204 var setter = property && property . set
189205
190- // if doNotObserve is true, only use the child value observer
191- // if it already exists, and do not attempt to create it.
192- // this allows freezing a large object from the root and
193- // avoid unnecessary observation inside v-for fragments.
194- var childOb = doNotObserve
195- ? isObject ( val ) && val . __ob__
196- : observe ( val )
206+ var childOb = observe ( val )
197207 Object . defineProperty ( obj , key , {
198208 enumerable : true ,
199209 configurable : true ,
@@ -223,9 +233,7 @@ export function defineReactive (obj, key, val, doNotObserve) {
223233 } else {
224234 val = newVal
225235 }
226- childOb = doNotObserve
227- ? isObject ( newVal ) && newVal . __ob__
228- : observe ( newVal )
236+ childOb = observe ( newVal )
229237 dep . notify ( )
230238 }
231239 } )
0 commit comments