File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function Observer (value) {
25
25
: copyAugment
26
26
augment ( value , arrayMethods , arrayKeys )
27
27
this . observeArray ( value )
28
- } else if ( _ . isPlainObject ( value ) ) {
28
+ } else {
29
29
this . walk ( value )
30
30
}
31
31
}
@@ -52,11 +52,18 @@ Observer.create = function (value, vm) {
52
52
) {
53
53
ob = value . __ob__
54
54
} else if (
55
- _ . isObject ( value ) &&
55
+ ( _ . isArray ( value ) || _ . isPlainObject ( value ) ) &&
56
56
! Object . isFrozen ( value ) &&
57
57
! value . _isVue
58
58
) {
59
59
ob = new Observer ( value )
60
+ } else if ( process . env . NODE_ENV !== 'production' ) {
61
+ if ( _ . isObject ( value ) && ! _ . isArray ( value ) && ! _ . isPlainObject ( value ) ) {
62
+ _ . warn (
63
+ 'Unobservable object found in data: ' +
64
+ Object . prototype . toString . call ( value )
65
+ )
66
+ }
60
67
}
61
68
if ( ob && vm ) {
62
69
ob . addVm ( vm )
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ var _ = require('../../../../src/util')
5
5
6
6
describe ( 'Observer' , function ( ) {
7
7
8
+ beforeEach ( function ( ) {
9
+ spyOn ( _ , 'warn' )
10
+ } )
11
+
8
12
it ( 'create on non-observables' , function ( ) {
9
13
// skip primitive value
10
14
var ob = Observer . create ( 1 )
@@ -193,4 +197,9 @@ describe('Observer', function () {
193
197
config . proto = true
194
198
} )
195
199
200
+ it ( 'warn unobservable object' , function ( ) {
201
+ Observer . create ( window )
202
+ expect ( hasWarned ( _ , 'Unobservable object found in data' ) ) . toBe ( true )
203
+ } )
204
+
196
205
} )
You can’t perform that action at this time.
0 commit comments