Skip to content

Commit

Permalink
Merge pull request #1063 from bertdeblock/improve-ember-data-decorato…
Browse files Browse the repository at this point in the history
…r-usage-examples

Use Ember Data decorators without parens where possible (#669)
  • Loading branch information
chancancode authored Sep 30, 2019
2 parents 8d748b4 + a80d144 commit 619b272
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions guides/release/models/customizing-serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ Ember Data's own `JSONAPISerializer` assumes types are plural and it
will automatically singularize the types.

Second, attribute and relationship names in the JSON:API document
should exactly match the name and casing of the `attr()`,
`belongsTo()` and `hasMany()`, properties defined on the
should exactly match the name and casing of the `@attr`,
`@belongsTo` and `@hasMany`, properties defined on the
Model.

By convention these property names are camelCase in Ember Data models.
Expand Down
16 changes: 8 additions & 8 deletions guides/release/models/defining-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import DS from 'ember-data';
const { Model, attr } = DS;

export default class Person extends Model {
@attr() firstName;
@attr() lastName;
@attr() birthday;
@attr firstName;
@attr lastName;
@attr birthday;
}
```

Expand All @@ -64,8 +64,8 @@ import DS from 'ember-data';
const { Model, attr } = DS;

export default class Person extends Model {
@attr() firstName;
@attr() lastName;
@attr firstName;
@attr lastName;

get fullName() {
return `${this.firstName} ${this.lastName}`;
Expand Down Expand Up @@ -177,14 +177,14 @@ When the API returns a deeply nested, read-only object or array,
there is no need to create multiple models with `attr('hasMany')` or `attr('belongsTo')`
relationships. This could result in a potentially large amount of unnecessary
code. You can access these objects in the template without transforming them. This can be
done with `attr()` (No attribute type).
done with `@attr` (No attribute type).

The following example shows how to define these attributes without transforming them
and accessing them within a template:

```javascript
@attr() location; // a read-only object
@attr() tags; // a read-only array
@attr location; // a read-only object
@attr tags; // a read-only array
```

```handlebars
Expand Down
6 changes: 3 additions & 3 deletions guides/release/models/pushing-records-into-the-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import DS from 'ember-data';
const { Model, attr } = DS;

export default class Album extends Model {
@attr() title;
@attr() artist;
@attr() songCount;
@attr title;
@attr artist;
@attr songCount;
}
```

Expand Down
6 changes: 3 additions & 3 deletions guides/release/models/relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ import PaymentMethod from './payment-method';
const { attr } = DS;

export default class PaymentMethodCc extends PaymentMethod {
@attr() last4;
@attr last4;

get obfuscatedIdentifier() {
return `**** **** **** ${this.last4}`;
Expand All @@ -200,7 +200,7 @@ import PaymentMethod from './payment-method'
const { attr } = DS;

export default class PaymentMethodPaypal extends PaymentMethod {
@attr() linkedEmail;
@attr linkedEmail;

get obfuscatedIdentifier() {
let last5 = this.linkedEmail.split('').reverse().slice(0, 5).reverse().join('');
Expand Down Expand Up @@ -266,7 +266,7 @@ relationship. However, since readonly data will never need to be
updated and saved this often results in the creation of a great deal
of code for very little benefit. An alternate approach is to define
these relationships using an attribute with no transform
(`attr()`). This makes it easy to access readonly values in
(`@attr`). This makes it easy to access readonly values in
other objects and templates without the overhead of defining
extraneous models.

Expand Down

0 comments on commit 619b272

Please sign in to comment.