Skip to content

Commit 0d77f75

Browse files
authored
Merge pull request #745 from bmish/docs-remove-this-get
Replace `this.get('property')` with `this.property` in rule examples
2 parents 1d73700 + bb7ec19 commit 0d77f75

10 files changed

+20
-24
lines changed

docs/rules/avoid-leaking-state-in-ember-objects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default Foo.extend({
1212

1313
actions: {
1414
addItem(item) {
15-
this.get('items').pushObject(item);
15+
this.items.pushObject(item);
1616
}
1717
}
1818
});
@@ -30,7 +30,7 @@ export default Foo.extend({
3030

3131
actions: {
3232
addItem(item) {
33-
this.get('items').pushObject(item);
33+
this.items.pushObject(item);
3434
}
3535
}
3636
});

docs/rules/no-attrs-in-components.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ const name = this.attrs.name;
1717
Examples of **correct** code for this rule:
1818

1919
```js
20-
import { get } from '@ember/object';
21-
2220
// Prefix private properties with _
23-
const name = get(this, '_name');
21+
const name = this._name;
2422
```
2523

2624
## Further Reading

docs/rules/no-mixins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import { isValidClassName } from 'my-utils';
5252

5353
export default Component.extend({
5454
aComputedProperty: computed('obj', function () {
55-
return isValidClassName(get(obj, 'className'));
55+
return isValidClassName(obj.className);
5656
})
5757
});
5858
```

docs/rules/no-new-mixins.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import myMixin from 'my-mixin';
3232

3333
export default Component.extend(myMixin, {
3434
aComputedProperty: computed('obj', function () {
35-
return this.isValidClassName(get(obj, 'className'));
35+
return this.isValidClassName(obj.className);
3636
})
3737
});
3838
```
@@ -56,7 +56,7 @@ import { isValidClassName } from 'my-utils';
5656

5757
export default Component.extend({
5858
aComputedProperty: computed('obj', function () {
59-
return isValidClassName(get(obj, 'className'));
59+
return isValidClassName(obj.className);
6060
})
6161
});
6262
```

docs/rules/no-side-effects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default Component.extend({
3131
// BAD:
3232
fifteenAmountBad: 0,
3333
fifteenBad: computed('users', function () {
34-
const fifteen = this.get('users').filterBy('items', 'age', 15);
34+
const fifteen = this.users.filterBy('items', 'age', 15);
3535
this.set('fifteenAmount', fifteen.length); // SIDE EFFECT!
3636
return fifteen;
3737
})

docs/rules/order-in-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default Component.extend({
107107

108108
// 5. Multiline Computed Property
109109
levelOfHappiness: computed('attitude', 'health', function () {
110-
const result = this.get('attitude') * this.get('health') * Math.random();
110+
const result = this.attitude * this.health * Math.random();
111111
return result;
112112
}),
113113

docs/rules/order-in-controllers.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ You should write code grouped and ordered in this way:
6666
const {
6767
Controller,
6868
computed,
69-
inject: { controller, service },
70-
get
69+
inject: { controller, service }
7170
} = Ember;
7271

7372
export default Controller.extend({
@@ -91,7 +90,7 @@ export default Controller.extend({
9190

9291
// 7. Multiline Computed Property
9392
levelOfHappiness: computed('attitude', 'health', function () {
94-
return get(this, 'attitude') * get(this, 'health') * Math.random();
93+
return this.attitude * this.health * Math.random();
9594
}),
9695

9796
// 8. Observers

docs/rules/order-in-models.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default Model.extend({
6363

6464
// 3. Computed Properties
6565
mood: computed('health', 'hunger', function () {
66-
const result = this.get('health') * this.get('hunger');
66+
const result = this.health * this.hunger;
6767
return result;
6868
})
6969
});
@@ -73,7 +73,7 @@ export default Model.extend({
7373
// BAD
7474
export default Model.extend({
7575
mood: computed('health', 'hunger', function () {
76-
const result = this.get('health') * this.get('hunger');
76+
const result = this.health * this.hunger;
7777
return result;
7878
}),
7979

docs/rules/order-in-routes.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ You should write code grouped and ordered in this way:
8484
```javascript
8585
const {
8686
Route,
87-
inject: { service },
88-
get
87+
inject: { service }
8988
} = Ember;
9089

9190
export default Route.extend({
@@ -102,7 +101,7 @@ export default Route.extend({
102101

103102
// 4. beforeModel hook
104103
beforeModel() {
105-
if (!get(this, 'currentUser.isAdmin')) {
104+
if (!this.currentUser.isAdmin) {
106105
this.transitionTo('index');
107106
}
108107
},

docs/rules/require-return-from-computed.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default Component.extend({
1717

1818
fullName: computed('firstName', 'lastName', {
1919
get() {
20-
return `${this.get('firstName')} ${this.get('lastName')}`;
20+
return `${this.firstName} ${this.lastName}`;
2121
},
2222
set(key, value) {
2323
const [firstName, lastName] = value.split(/\s+/);
@@ -27,8 +27,8 @@ export default Component.extend({
2727
}),
2828

2929
salutation: computed('firstName', function () {
30-
if (this.get('firstName')) {
31-
return `Dr. ${this.get('firstName')}`;
30+
if (this.firstName) {
31+
return `Dr. ${this.firstName}`;
3232
}
3333
})
3434
});
@@ -46,7 +46,7 @@ export default Component.extend({
4646

4747
fullName: computed('firstName', 'lastName', {
4848
get() {
49-
return `${this.get('firstName')} ${this.get('lastName')}`;
49+
return `${this.firstName} ${this.lastName}`;
5050
},
5151
set(key, value) {
5252
const [firstName, lastName] = value.split(/\s+/);
@@ -57,8 +57,8 @@ export default Component.extend({
5757
}),
5858

5959
salutation: computed('firstName', function () {
60-
if (this.get('firstName')) {
61-
return `Dr. ${this.get('firstName')}`;
60+
if (this.firstName) {
61+
return `Dr. ${this.firstName}`;
6262
}
6363
return '';
6464
})

0 commit comments

Comments
 (0)