Skip to content

Commit 2d4cd3b

Browse files
authored
Octane - Replace some references to Computed Properties with Tracked (ember-learn#805)
* change some mentioned of CPs to tracked/getters * replace more CPs * Apply suggestions from code review Co-Authored-By: Robert Jackson <[email protected]> * update following rwjblue's suggestions
1 parent 1d230c4 commit 2d4cd3b

File tree

10 files changed

+22
-26
lines changed

10 files changed

+22
-26
lines changed

guides/release/applications/dependency-injection.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,29 +234,28 @@ For example, this component plays songs with different audio services based
234234
on a song's `audioType`.
235235

236236
```javascript {data-filename=app/components/play-audio.js}
237-
import Component from '@ember/component';
238-
import { computed } from '@ember/object';
237+
import Component from '@glimmer/component';
239238
import { getOwner } from '@ember/application';
240239

241240
// Usage:
242241
//
243-
// {{play-audio song=song}}
242+
// <PlayAudio @song=this.song />
244243
//
245-
export default Component.extend({
246-
audioService: computed('song.audioType', function() {
247-
if (!this.song) {
244+
export default class PlayAudioComponent extends Component {
245+
get audioService() {
246+
if (!this.args.song) {
248247
return null;
249248
}
250249

251250
let applicationInstance = getOwner(this);
252-
let audioType = this.song.audioType;
251+
let { audioType } = this.args.song;
253252

254253
return applicationInstance.lookup(`service:audio-${audioType}`);
255-
}),
254+
}
256255

257256
click() {
258257
let player = this.audioService;
259-
player.play(this.song.file);
258+
player.play(this.args.song.file);
260259
}
261-
});
260+
}
262261
```

guides/release/controllers/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Controllers are used as an extension of the model loaded from the Route. Any att
2727

2828
Controllers are singletons so we should avoid keeping state that does not derive from either the Model or Query Parameters since these would persist in between activations such as when a user leaves the Route and then re-enters it.
2929

30-
Controllers can also contain actions that enable the Route's components to update the Model or Query Parameters through it using Computed Properties.
30+
Controllers can also contain actions, Query Parameters, Tracked Properties, and more.
3131

3232
### Basic Controller Example
3333

@@ -103,5 +103,5 @@ Yes! Controllers are still an integral part of an Ember application architecture
103103
#### When should we create a Controller?
104104

105105
* We want to pass down actions or variables to share with a Route’s child components
106-
* We have a computed property that depends on the results of the model hook
106+
* We need to compute a value based on the results of the model hook
107107
* We need to support query parameters

guides/release/models/relationships.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ updated and saved this often results in the creation of a great deal
267267
of code for very little benefit. An alternate approach is to define
268268
these relationships using an attribute with no transform
269269
(`attr()`). This makes it easy to access readonly values in
270-
computed properties and templates without the overhead of defining
270+
other objects and templates without the overhead of defining
271271
extraneous models.
272272

273273
### Creating Records

guides/release/routing/query-params.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ and the `category` property on `controller:articles`. In other words,
4141
once the `articles` route has been entered, any changes to the
4242
`category` query param in the URL will update the `category` property
4343
on `controller:articles`, and vice versa.
44-
Note that you can't bind `queryParams` to computed properties, they
44+
Note that you can't make `queryParams` be a dynamically generated property (neither computed property, nor property getter); they
4545
have to be values.
4646

47-
Now we need to define a computed property of our category-filtered
48-
array that the `articles` template will render:
47+
Now we need to define a getter for our category-filtered
48+
array, which the `articles` template will render. For the getter to recompute when values change, `category` and `model` should be marked as tracked properties:
4949

5050
```javascript {data-filename=app/controllers/articles.js}
5151
import Controller from '@ember/controller';
52-
import { computed } from '@ember/object';
5352

5453
export default class ArticlesController extends Controller {
5554
queryParams = ['category'];

guides/release/services/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@ you must look up the service using Ember's [`getOwner`](https://emberjs.com/api/
9292

9393
```javascript {data-filename=app/components/cart-contents.js}
9494
import Component from '@glimmer/component';
95-
import { computed } from '@ember/object';
9695
import { getOwner } from '@ember/application';
9796

9897
export default class CartContentsComponent extends Component {
9998
//will load the service in file /app/services/shopping-cart.js
100-
@computed
10199
get cart() {
102100
return getOwner(this).lookup('service:shopping-cart');
103101
}

guides/release/templates/built-in-helpers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ API documentation.
1414
The [`{{get}}`](https://www.emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/get?anchor=get)
1515
helper makes it easy to dynamically send the value of a variable to another
1616
helper or component. This can be useful if you want to output one of several
17-
values based on the result of a computed property.
17+
values based on the result of a getter.
1818

1919
```handlebars
2020
{{get this.address this.part}}
2121
```
2222

23-
if the `part` computed property returns "zip", this will display the result of `this.address.zip`.
23+
If the `part` getter returns "zip", this will display the result of `this.address.zip`.
2424
If it returns "city", you get `this.address.city`.
2525

2626
### The `concat` helper

guides/release/testing/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Notice how there is nothing Ember specific about the test, it is just a straight
2727
Examples of Unit Tests are:
2828

2929
* The return value of a `getFullName` utility combines its `firstName` and `lastName` parameters correctly.
30-
* A computed property macro formats a price depending on its `currency` and `cents` dependent keys.
30+
* A getter formats a price depending on tracked properties like `currency` and `cents` .
3131
* A utility function that adds padding on a string based on the value passed.
3232

3333
Unit Tests are useful for testing pure functions where the return value is only determined by its input values, without any observable side effects.
@@ -64,7 +64,7 @@ Container Tests are ideal for testing Controllers, Routes, or Services where we
6464

6565
Examples of Container Tests are:
6666

67-
* A `fullName` attribute on a controller is computed by combining its `firstName` and `lastName` attributes.
67+
* A `fullName` attribute on a controller is a getter that combines the tracked properties `firstName` and `lastName`.
6868
* A serializer properly converts the blog request payload into a blog post model object.
6969
* Blog dates are properly formatted through a `time` service.
7070

guides/release/testing/testing-controllers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_Container testing methods and computed properties follow previous patterns shown
1+
_Container testing methods and getters follow previous patterns shown
22
in [Testing Basics][] because Ember.Controller extends Ember.Object._
33

44
Controllers can be tested using the `setupTest` helper which is part

guides/release/testing/testing-models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_Container testing methods and computed properties follow previous patterns shown
1+
_Container testing methods and getters follow previous patterns shown
22
in [Testing Basics][] because DS.Model extends Ember.Object._
33

44
[Ember Data][] Models can be tested in a module that uses the `setupTest` helper.

guides/release/testing/testing-routes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_Container testing methods and computed properties follow previous patterns shown
1+
_Container testing methods and getters follow previous patterns shown
22
in [Testing Basics][] because Ember.Route extends Ember.Object._
33

44
Testing routes can be done both via application tests or container tests. Application tests

0 commit comments

Comments
 (0)