Skip to content

Commit

Permalink
computed properties should be cached by default
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 25, 2015
1 parent b954689 commit 3fc91b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/instance/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ exports._initComputed = function () {
configurable: true
}
if (typeof userDef === 'function') {
def.get = _.bind(userDef, this)
def.get = makeComputedGetter(userDef, this)
def.set = noop
} else {
def.get = userDef.get
? userDef.cache
? userDef.cache !== false
? makeComputedGetter(userDef.get, this)
: _.bind(userDef.get, this)
: noop
Expand Down
22 changes: 20 additions & 2 deletions test/unit/specs/instance/scope_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ describe('Instance Scope', function () {
},
// cached
f: {
cache: true,
get: function () {
spyF()
return this.ff
Expand All @@ -192,7 +191,6 @@ describe('Instance Scope', function () {
},
// another cached, for watcher test
h: {
cache: true,
get: function () {
return this.hh
}
Expand Down Expand Up @@ -305,6 +303,26 @@ describe('Instance Scope', function () {
expect(vm.e).toBe('CDe')
})

it('disable cache', function () {
var external = { b: 'B' }
var vm = new Vue({
data: {
a: 'A'
},
computed: {
test: {
cache: false,
get: function () {
return this.a + external.b
}
}
}
})
expect(vm.test).toBe('AB')
external.b = 'C'
expect(vm.test).toBe('AC')
})

})

describe('methods', function () {
Expand Down

0 comments on commit 3fc91b9

Please sign in to comment.