@@ -2,7 +2,6 @@ import Dep from './dep'
2
2
import { arrayMethods } from './array'
3
3
import {
4
4
def ,
5
- isObject ,
6
5
isArray ,
7
6
isPlainObject ,
8
7
hasProto ,
@@ -11,6 +10,23 @@ import {
11
10
12
11
const arrayKeys = Object . getOwnPropertyNames ( arrayMethods )
13
12
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
+
14
30
/**
15
31
* Observer class that are attached to each observed
16
32
* object. Once attached, the observer converts target
@@ -154,6 +170,7 @@ export function observe (value, vm) {
154
170
) {
155
171
ob = value . __ob__
156
172
} else if (
173
+ shouldConvert &&
157
174
( isArray ( value ) || isPlainObject ( value ) ) &&
158
175
Object . isExtensible ( value ) &&
159
176
! value . _isVue
@@ -172,10 +189,9 @@ export function observe (value, vm) {
172
189
* @param {Object } obj
173
190
* @param {String } key
174
191
* @param {* } val
175
- * @param {Boolean } doNotObserve
176
192
*/
177
193
178
- export function defineReactive ( obj , key , val , doNotObserve ) {
194
+ export function defineReactive ( obj , key , val ) {
179
195
var dep = new Dep ( )
180
196
181
197
var property = Object . getOwnPropertyDescriptor ( obj , key )
@@ -187,13 +203,7 @@ export function defineReactive (obj, key, val, doNotObserve) {
187
203
var getter = property && property . get
188
204
var setter = property && property . set
189
205
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 )
197
207
Object . defineProperty ( obj , key , {
198
208
enumerable : true ,
199
209
configurable : true ,
@@ -223,9 +233,7 @@ export function defineReactive (obj, key, val, doNotObserve) {
223
233
} else {
224
234
val = newVal
225
235
}
226
- childOb = doNotObserve
227
- ? isObject ( newVal ) && newVal . __ob__
228
- : observe ( newVal )
236
+ childOb = observe ( newVal )
229
237
dep . notify ( )
230
238
}
231
239
} )
0 commit comments