Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLEANUP beta] Remove deprecated CP semantics #11438

Merged
merged 1 commit into from
Jun 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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