Skip to content

Commit 28a2c68

Browse files
author
Evan You
committed
should not observer other Vue instances
1 parent 218557c commit 28a2c68

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/observer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ var Emitter = require('./emitter'),
1616
// define methods as inenumerable if __proto__ is present,
1717
// otherwise enumerable so we can loop through and manually
1818
// attach to array instances
19-
hasProto = ({}).__proto__
19+
hasProto = ({}).__proto__,
20+
21+
// lazy load
22+
ViewModel
2023

2124
// The proxy prototype to replace the __proto__ of
2225
// an observed array
@@ -161,8 +164,9 @@ function bind (obj, key, path, observer) {
161164
* Check if a value is watchable
162165
*/
163166
function isWatchable (obj) {
167+
ViewModel = ViewModel || require('./viewmodel')
164168
var type = typeOf(obj)
165-
return type === 'Object' || type === 'Array'
169+
return (type === 'Object' || type === 'Array') && !(obj instanceof ViewModel)
166170
}
167171

168172
/**

test/unit/specs/observer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ describe('UNIT: Observer', function () {
55
DepsOb = require('vue/src/deps-parser').observer
66

77
describe('Observing Object', function () {
8+
9+
it('should not watch a ViewModel instance', function () {
10+
var obj = new Vue(), ob = new Emitter()
11+
ob.proxies = {}
12+
Observer.observe(obj, 'test', ob)
13+
assert.notOk(obj.__observer__)
14+
})
815

916
it('should attach hidden observer and values to the object', function () {
1017
var obj = {}, ob = new Emitter()

0 commit comments

Comments
 (0)