Skip to content

Commit

Permalink
Merge pull request #11438 from cibernox/remove-deprecated-cp-behavior
Browse files Browse the repository at this point in the history
[CLEANUP beta] Remove deprecated CP semantics
  • Loading branch information
mixonic committed Jun 14, 2015
2 parents a9e3831 + d5a2935 commit 6cb71d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 108 deletions.
53 changes: 5 additions & 48 deletions packages/ember-metal/lib/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
}
Expand Down
60 changes: 0 additions & 60 deletions packages/ember-metal/tests/computed_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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 = { };

Expand Down

0 comments on commit 6cb71d7

Please sign in to comment.