From d5a29355616f09325530594ae415bc391958c609 Mon Sep 17 00:00:00 2001 From: Miguel Camba Date: Wed, 10 Jun 2015 18:03:26 +0100 Subject: [PATCH] Remove deprecated CP semantics --- packages/ember-metal/lib/computed.js | 53 ++---------------- packages/ember-metal/tests/computed_test.js | 60 --------------------- 2 files changed, 5 insertions(+), 108 deletions(-) diff --git a/packages/ember-metal/lib/computed.js b/packages/ember-metal/lib/computed.js index 3f0a348d945..e6eb485a822 100644 --- a/packages/ember-metal/lib/computed.js +++ b/packages/ember-metal/lib/computed.js @@ -115,60 +115,23 @@ function UNDEFINED() { } function ComputedProperty(config, opts) { this.isDescriptor = true; if (typeof config === "function") { - config.__ember_arity = config.length; this._getter = config; - if (config.__ember_arity > 1) { - Ember.deprecate("Using the same function as getter and setter is deprecated.", false, { - url: "http://emberjs.com/deprecations/v1.x/#toc_deprecate-using-the-same-function-as-getter-and-setter-in-computed-properties" - }); - this._setter = config; - } } else { this._getter = config.get; this._setter = config.set; - if (this._setter && this._setter.__ember_arity === undefined) { - this._setter.__ember_arity = this._setter.length; - } } - this._dependentKeys = undefined; this._suspended = undefined; this._meta = undefined; - - Ember.deprecate("Passing opts.cacheable to the CP constructor is deprecated. Invoke `volatile()` on the CP instead.", !opts || !opts.hasOwnProperty('cacheable')); - this._cacheable = (opts && opts.cacheable !== undefined) ? opts.cacheable : true; // TODO: Set always to `true` once this deprecation is gone. + this._cacheable = true; this._dependentKeys = opts && opts.dependentKeys; - Ember.deprecate("Passing opts.readOnly to the CP constructor is deprecated. All CPs are writable by default. You can invoke `readOnly()` on the CP to change this.", !opts || !opts.hasOwnProperty('readOnly')); - this._readOnly = opts && (opts.readOnly !== undefined || !!opts.readOnly) || false; // TODO: Set always to `false` once this deprecation is gone. + this._readOnly = false; } ComputedProperty.prototype = new Descriptor(); var ComputedPropertyPrototype = ComputedProperty.prototype; -/** - Properties are cacheable by default. Computed property will automatically - cache the return value of your function until one of the dependent keys changes. - - Call `volatile()` to set it into non-cached mode. When in this mode - the computed property will not automatically cache the return value. - - However, if a property is properly observable, there is no reason to disable - caching. - - @method cacheable - @param {Boolean} aFlag optional set to `false` to disable caching - @return {Ember.ComputedProperty} this - @chainable - @deprecated All computed properties are cacheble by default. Use `volatile()` instead to opt-out to caching. - @public -*/ -ComputedPropertyPrototype.cacheable = function(aFlag) { - Ember.deprecate('ComputedProperty.cacheable() is deprecated. All computed properties are cacheable by default.'); - this._cacheable = aFlag !== false; - return this; -}; - /** Call on a computed property to set it into non-cached mode. When in this mode the computed property will not automatically cache the return value. @@ -212,9 +175,8 @@ ComputedPropertyPrototype.volatile = function() { @chainable @public */ -ComputedPropertyPrototype.readOnly = function(readOnly) { - Ember.deprecate('Passing arguments to ComputedProperty.readOnly() is deprecated.', arguments.length === 0); - this._readOnly = readOnly === undefined || !!readOnly; // Force to true once this deprecation is gone +ComputedPropertyPrototype.readOnly = function() { + this._readOnly = true; Ember.assert("Computed properties that define a setter using the new syntax cannot be read-only", !(this._readOnly && this._setter && this._setter !== this._getter)); return this; }; @@ -464,12 +426,7 @@ ComputedPropertyPrototype._set = function computedPropertySet(obj, keyName, valu if (!setter) { defineProperty(obj, keyName, null, cachedValue); - set(obj, keyName, value); - return; - } else if (setter.__ember_arity === 2) { - // Is there any way of deprecate this in a sensitive way? - // Maybe now that getters and setters are the prefered options we can.... - ret = setter.call(obj, keyName, value); + return set(obj, keyName, value); } else { ret = setter.call(obj, keyName, value, cachedValue); } diff --git a/packages/ember-metal/tests/computed_test.js b/packages/ember-metal/tests/computed_test.js index 38a43fe3f3b..ca29545d07f 100644 --- a/packages/ember-metal/tests/computed_test.js +++ b/packages/ember-metal/tests/computed_test.js @@ -233,32 +233,6 @@ testBoth('modifying a cacheable property should update cache', function(get, set equal(count, 2, 'should not invoke again'); }); -QUnit.test('calling cacheable() on a computed property raises a deprecation', function() { - var cp = new ComputedProperty(function() {}); - expectDeprecation(function() { - cp.cacheable(); - }, 'ComputedProperty.cacheable() is deprecated. All computed properties are cacheable by default.'); -}); - -QUnit.test('passing cacheable in a the options to the CP constructor raises a deprecation', function() { - expectDeprecation(function() { - new ComputedProperty(function() {}, { cacheable: true }); - }, "Passing opts.cacheable to the CP constructor is deprecated. Invoke `volatile()` on the CP instead."); -}); - -QUnit.test('calling readOnly() on a computed property with arguments raises a deprecation', function() { - var cp = new ComputedProperty(function() {}); - expectDeprecation(function() { - cp.readOnly(true); - }, 'Passing arguments to ComputedProperty.readOnly() is deprecated.'); -}); - -QUnit.test('passing readOnly in a the options to the CP constructor raises a deprecation', function() { - expectDeprecation(function() { - new ComputedProperty(function() {}, { readOnly: false }); - }, "Passing opts.readOnly to the CP constructor is deprecated. All CPs are writable by default. You can invoke `readOnly()` on the CP to change this."); -}); - testBoth('inherited property should not pick up cache', function(get, set) { var objB = create(obj); @@ -319,25 +293,6 @@ testBoth("setting a cached computed property passes the old value as the third a strictEqual(receivedOldValue, 2, "oldValue should be 2"); }); -testBoth("the old value is only passed in if the computed property specifies three arguments", function(get, set) { - var obj = { - foo: 0 - }; - - defineProperty(obj, 'plusOne', computed({ - get: function() {}, - set: function(key, value) { - equal(arguments.length, 2, "computed property is only invoked with two arguments"); - return value; - } - }).property('foo') - ); - - set(obj, 'plusOne', 1); - set(obj, 'plusOne', 2); - set(obj, 'plusOne', 3); -}); - // .......................................................... // DEPENDENT KEYS // @@ -701,15 +656,6 @@ QUnit.test('the return value of the setter gets cached', function() { ok(testObj.get('sampleCP') === 'set-value', 'The return value of the CP was cached'); }); -QUnit.test('Passing a function that acts both as getter and setter is deprecated', function() { - var regex = /Using the same function as getter and setter is deprecated/; - expectDeprecation(function() { - Ember.Object.extend({ - aInt: computed('a', function(keyName, value, oldValue) {}) - }); - }, regex); -}); - // .......................................................... // BUGS // @@ -885,12 +831,6 @@ QUnit.test('throws assertion if called over a CP with a setter defined with the }, /Computed properties that define a setter using the new syntax cannot be read-only/); }); -QUnit.test('doesn\'t throws assertion if called over a CP with a setter defined with the old syntax', function() { - expectDeprecation(function() { - computed(function(key, value) {}).readOnly(); - }, /same function as getter and setter/); -}); - testBoth('protects against setting', function(get, set) { var obj = { };