Browse Source

cache computed by default (regression in #1232)

Evan You 10 years ago
parent
commit
c4f307c650
3 changed files with 9 additions and 19 deletions
  1. 0 7
      src/deprecations.js
  2. 2 7
      src/instance/state.js
  3. 7 5
      test/unit/specs/instance/state_spec.js

+ 0 - 7
src/deprecations.js

@@ -144,13 +144,6 @@ if (process.env.NODE_ENV !== 'production') {
       )
     },
 
-    COMPUTED_CACHE: function (name) {
-      warn(
-        'Computed property "' + name + '": computed properties are not cached by ' +
-        'default in 1.0.0. You only need to enable cache for particularly expensive ones.'
-      )
-    },
-
     BIND_IS: function () {
       warn(
         '<component is="{{view}}"> syntax will be deprecated in 1.0.0. Use ' +

+ 2 - 7
src/instance/state.js

@@ -199,16 +199,11 @@ exports._initComputed = function () {
         configurable: true
       }
       if (typeof userDef === 'function') {
-        def.get = _.bind(userDef, this)
+        def.get = makeComputedGetter(userDef, this)
         def.set = noop
       } else {
-
-        if (process.env.NODE_ENV !== 'production' && userDef.cache === false) {
-          _.deprecation.COMPUTED_CACHE(key)
-        }
-
         def.get = userDef.get
-          ? userDef.cache
+          ? userDef.cache !== false
             ? makeComputedGetter(userDef.get, this)
             : _.bind(userDef.get, this)
           : noop

+ 7 - 5
test/unit/specs/instance/state_spec.js

@@ -161,11 +161,15 @@ describe('Instance state initialization', function () {
 
     var Test = Vue.extend({
       computed: {
-        c: function () {
-          return this.a + this.b
+        // uncached
+        c: {
+          cache: false,
+          get: function () {
+            return this.a + this.b
+          }
         },
+        // with setter
         d: {
-          cache: false, // for deprecation coverage. TODO: remove in 1.0.0
           get: function () {
             return this.a + this.b
           },
@@ -181,7 +185,6 @@ describe('Instance state initialization', function () {
         },
         // cached
         f: {
-          cache: true,
           get: function () {
             spyF()
             return this.ff
@@ -193,7 +196,6 @@ describe('Instance state initialization', function () {
         },
         // another cached, for watcher test
         h: {
-          cache: true,
           get: function () {
             return this.hh
           }