From 02e929093dd8c1019cc1e58f8fcfb1b8ccb79534 Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Fri, 27 Mar 2015 09:09:27 -0700 Subject: [PATCH 1/3] prefer non prototype extension annotation of computed properties --- source/concepts/what-is-ember-js.md | 19 ++++--- ...ng-a-single-model-with-objectcontroller.md | 10 ++-- ...ng-multiple-models-with-arraycontroller.md | 10 ++-- ..._to_your_components_based_on_properties.md | 4 +- .../basic_form_validations.md | 5 +- ..._strings_to_currency_with_accounting_js.md | 6 +- ...splaying_formatted_dates_with_moment_js.md | 11 ++-- .../continuous_redrawing_of_views.md | 56 ++++++++++--------- ...playing_content_arrays_in_reverse_order.md | 8 +-- source/models/defining-models.md | 4 +- .../computed-properties-and-aggregate-data.md | 19 ++++--- source/object-model/computed-properties.md | 26 +++------ source/object-model/observers.md | 4 +- source/routing/query-params.md | 4 +- source/templates/rendering-with-helpers.md | 8 +-- source/testing/testing-components.md | 12 ++-- source/testing/unit-testing-basics.md | 4 +- .../record-lifecycle.md | 4 +- .../managing-asynchrony.md | 8 +-- source/understanding-ember/run-loop.md | 4 +- 20 files changed, 113 insertions(+), 113 deletions(-) diff --git a/source/concepts/what-is-ember-js.md b/source/concepts/what-is-ember-js.md index ba1ce95ca..800b177bc 100644 --- a/source/concepts/what-is-ember-js.md +++ b/source/concepts/what-is-ember-js.md @@ -104,11 +104,11 @@ var president = Ember.Object.create({ firstName: "Barack", lastName: "Obama", - fullName: function() { + fullName: Ember.computed(function() { return this.get('firstName') + ' ' + this.get('lastName'); // Call this flag to mark the function as a property - }.property() + }) }); president.get('fullName'); @@ -124,15 +124,18 @@ You can tell Ember about these dependencies like this: ```javascript var president = Ember.Object.create({ - firstName: "Barack", - lastName: "Obama", + init: function() { + this._super.apply(this, arguments); + this.set('firstName', 'Barack'); + this.set('lastName', 'Obama'); + }, - fullName: function() { + fullName: Ember.computed('firstName', 'lastName', function() { return this.get('firstName') + ' ' + this.get('lastName'); - // Tell Ember that this computed property depends on firstName - // and lastName - }.property('firstName', 'lastName') + // Tell Ember that this computed property depends on firstName + // and lastName + }) }); ``` diff --git a/source/controllers/representing-a-single-model-with-objectcontroller.md b/source/controllers/representing-a-single-model-with-objectcontroller.md index 0e42ba83e..018a0ccfe 100644 --- a/source/controllers/representing-a-single-model-with-objectcontroller.md +++ b/source/controllers/representing-a-single-model-with-objectcontroller.md @@ -84,13 +84,13 @@ format for the template: ```app/controllers/song.js export default Ember.ObjectController.extend({ - duration: function() { - var duration = this.get('model.duration'), - minutes = Math.floor(duration / 60), - seconds = duration % 60; + duration: Ember.computed('model.duration', function() { + var duration = this.get('model.duration'); + var minutes = Math.floor(duration / 60); + var seconds = duration % 60; return [minutes, seconds].join(':'); - }.property('model.duration') + }) }); ``` diff --git a/source/controllers/representing-multiple-models-with-arraycontroller.md b/source/controllers/representing-multiple-models-with-arraycontroller.md index cf4397280..0579cafed 100644 --- a/source/controllers/representing-multiple-models-with-arraycontroller.md +++ b/source/controllers/representing-multiple-models-with-arraycontroller.md @@ -34,12 +34,12 @@ property called `longSongCount` to the controller: ```app/controllers/songs.js export default Ember.ArrayController.extend({ - longSongCount: function() { + longSongCount: Ember.computed('@each.duration', function() { var longSongs = this.filter(function(song) { return song.get('duration') > 30; }); return longSongs.get('length'); - }.property('@each.duration') + }) }); ``` @@ -75,11 +75,9 @@ creating an `ObjectController`: ```app/controllers/song.js export default Ember.ObjectController.extend({ - fullName: function() { - + fullName: Ember.computed('name', 'artist', function() { return this.get('name') + ' by ' + this.get('artist'); - - }.property('name', 'artist') + }) }); ``` diff --git a/source/cookbook/user_interface_and_interaction/adding_css_classes_to_your_components_based_on_properties.md b/source/cookbook/user_interface_and_interaction/adding_css_classes_to_your_components_based_on_properties.md index 5b0473d68..0b5a308d7 100644 --- a/source/cookbook/user_interface_and_interaction/adding_css_classes_to_your_components_based_on_properties.md +++ b/source/cookbook/user_interface_and_interaction/adding_css_classes_to_your_components_based_on_properties.md @@ -17,9 +17,9 @@ You can also set the class name based on a computed property. ```js classNameBindings: ['isActive'], -isActive: function() { +isActive: Ember.computed('someAttribute', function() { return 'active'; -}.property('someAttribute') +}) ``` Another way would be to bind the class name to a bound property. diff --git a/source/cookbook/user_interface_and_interaction/basic_form_validations.md b/source/cookbook/user_interface_and_interaction/basic_form_validations.md index fbb8e6038..0456826ed 100644 --- a/source/cookbook/user_interface_and_interaction/basic_form_validations.md +++ b/source/cookbook/user_interface_and_interaction/basic_form_validations.md @@ -16,11 +16,12 @@ been focused. The component expects to get the validation result as the export default Ember.Component.extend({ beenFocused: false, valid: null, - hasError: function() { + hasError: Ember.computed('valid', 'beenFocused', function() { if (this.get('beenFocused')) { return !this.get('valid'); } - }.property('valid', 'beenFocused'), + }), + focusOut: function() { this.set('beenFocused', true); } diff --git a/source/cookbook/user_interface_and_interaction/converting_strings_to_currency_with_accounting_js.md b/source/cookbook/user_interface_and_interaction/converting_strings_to_currency_with_accounting_js.md index 81bbd3a03..54d6940bc 100644 --- a/source/cookbook/user_interface_and_interaction/converting_strings_to_currency_with_accounting_js.md +++ b/source/cookbook/user_interface_and_interaction/converting_strings_to_currency_with_accounting_js.md @@ -10,15 +10,15 @@ Make use of the [computed property's setter][setters] to remove the display formatting and set the property to the proper value. ```js -formattedAmount: function(key, value) { +formattedAmount: Ember.computed('amount', function(key, value) { if (arguments.length > 1) { // setter var cleanAmount = accounting.unformat(value); this.set('amount', cleanAmount); } - + return accounting.formatMoney(this.get('amount')); -}.property('amount') +}); ```