Skip to content

Commit

Permalink
should not observer other Vue instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan You committed Dec 17, 2013
1 parent 218557c commit 28a2c68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ var Emitter = require('./emitter'),
// define methods as inenumerable if __proto__ is present,
// otherwise enumerable so we can loop through and manually
// attach to array instances
hasProto = ({}).__proto__
hasProto = ({}).__proto__,

// lazy load
ViewModel

// The proxy prototype to replace the __proto__ of
// an observed array
Expand Down Expand Up @@ -161,8 +164,9 @@ function bind (obj, key, path, observer) {
* Check if a value is watchable
*/
function isWatchable (obj) {
ViewModel = ViewModel || require('./viewmodel')
var type = typeOf(obj)
return type === 'Object' || type === 'Array'
return (type === 'Object' || type === 'Array') && !(obj instanceof ViewModel)
}

/**
Expand Down
7 changes: 7 additions & 0 deletions test/unit/specs/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ describe('UNIT: Observer', function () {
DepsOb = require('vue/src/deps-parser').observer

describe('Observing Object', function () {

it('should not watch a ViewModel instance', function () {
var obj = new Vue(), ob = new Emitter()
ob.proxies = {}
Observer.observe(obj, 'test', ob)
assert.notOk(obj.__observer__)
})

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

0 comments on commit 28a2c68

Please sign in to comment.