Skip to content

Commit

Permalink
Merge pull request #10950 from cibernox/es6-getters-setters-in-cps
Browse files Browse the repository at this point in the history
Use nicer ES6 syntax for get/set on CPs
  • Loading branch information
stefanpenner committed Apr 27, 2015
2 parents 6f090c9 + 0f66c76 commit 20d9700
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions packages/ember-metal/lib/computed_macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,12 @@ export function readOnly(dependentKey) {
*/
export function defaultTo(defaultPath) {
return computed({
get: function(key) {
get(key) {
Ember.deprecate('Usage of Ember.computed.defaultTo is deprecated, use `Ember.computed.oneWay` instead.');
return get(this, defaultPath);
},

set: function(key, newValue, cachedValue) {
set(key, newValue, cachedValue) {
Ember.deprecate('Usage of Ember.computed.defaultTo is deprecated, use `Ember.computed.oneWay` instead.');
return newValue != null ? newValue : get(this, defaultPath);
}
Expand All @@ -702,11 +702,11 @@ export function defaultTo(defaultPath) {
*/
export function deprecatingAlias(dependentKey) {
return computed(dependentKey, {
get: function(key) {
get(key) {
Ember.deprecate(`Usage of \`${key}\` is deprecated, use \`${dependentKey}\` instead.`);
return get(this, dependentKey);
},
set: function(key, value) {
set(key, value) {
Ember.deprecate(`Usage of \`${key}\` is deprecated, use \`${dependentKey}\` instead.`);
set(this, dependentKey, value);
return value;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-routing-views/lib/views/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ var LinkView = EmberComponent.extend({
@property disabled
*/
disabled: computed({
get: function(key, value) {
get(key, value) {
return false;
},
set: function(key, value) {
set(key, value) {
if (value !== undefined) { this.set('_isDisabled', value); }

return value ? get(this, 'disabledClass') : false;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/controllers/array_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ export default ArrayProxy.extend(ControllerMixin, SortableMixin, {
},

model: computed({
get: function(key) {
get(key) {
return Ember.A();
},
set: function(key, value) {
set(key, value) {
Ember.assert(
'ArrayController expects `model` to implement the Ember.Array mixin. ' +
'This can often be fixed by wrapping your model with `Ember.A()`.',
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ export default Mixin.create(Enumerable, {
@return this
*/
'[]': computed({
get: function(key) {
get(key) {
return this;
},
set: function(key, value) {
set(key, value) {
this.replace(0, get(this, 'length'), value);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/enumerable.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ export default Mixin.create({
@return this
*/
'[]': computed({
get: function(key) { return this; }
get(key) { return this; }
}),

// ..........................................................
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-runtime/lib/mixins/promise_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ export default Mixin.create({
@property promise
*/
promise: computed({
get: function() {
get() {
throw new EmberError("PromiseProxy's promise must be set");
},
set: function(key, promise) {
set(key, promise) {
return tap(this, promise);
}
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-runtime/lib/mixins/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default Mixin.create(MutableEnumerable, {
@property arrangedContent
*/
arrangedContent: computed('content', 'sortProperties.@each', {
get: function(key) {
get(key) {
var content = get(this, 'content');
var isSorted = get(this, 'isSorted');
var sortProperties = get(this, 'sortProperties');
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-views/lib/mixins/view_context_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var ViewContextSupport = Mixin.create({
@type Object
*/
context: computed({
get: function() {
get() {
return get(this, '_context');
},
set: function(key, value) {
set(key, value) {
set(this, '_context', value);
return value;
}
Expand All @@ -53,7 +53,7 @@ var ViewContextSupport = Mixin.create({
@private
*/
_context: computed({
get: function() {
get() {
var parentView, controller;

if (controller = get(this, 'controller')) {
Expand All @@ -66,7 +66,7 @@ var ViewContextSupport = Mixin.create({
}
return null;
},
set: function(key, value) {
set(key, value) {
return value;
}
}),
Expand All @@ -81,14 +81,14 @@ var ViewContextSupport = Mixin.create({
@type Object
*/
controller: computed({
get: function() {
get() {
if (this._controller) {
return this._controller;
}

return this._parentView ? get(this._parentView, 'controller') : null;
},
set: function(_, value) {
set(_, value) {
this._controller = value;
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/views/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,11 @@ var Select = View.extend({
@default null
*/
value: computed({
get: function(key) {
get(key) {
var valuePath = get(this, '_valuePath');
return valuePath ? get(this, 'selection.' + valuePath) : get(this, 'selection');
},
set: function(key, value) {
set(key, value) {
return value;
}
}).property('_valuePath', 'selection'),
Expand Down
4 changes: 2 additions & 2 deletions packages/ember-views/lib/views/text_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ function canSetTypeOfInput(type) {
function getTypeComputed() {
if (Ember.FEATURES.isEnabled('new-computed-syntax')) {
return computed({
get: function() {
get() {
return 'text';
},

set: function(key, value) {
set(key, value) {
var type = 'text';

if (canSetTypeOfInput(value)) {
Expand Down

0 comments on commit 20d9700

Please sign in to comment.