Skip to content

Remove unnecessary this.get() calls #2776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 20, 2020
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module.exports = {

'ember/no-classic-classes': 'error',
'ember/no-empty-attrs': 'off',
'ember/no-get': 'off',
'ember/require-computed-property-dependencies': 'off',

'import-helpers/order-imports': [
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/crate/owners.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export default class CrateOwnersController extends Controller {
switch (owner.kind) {
case 'user':
this.set('removed', `User ${owner.get('login')} removed as crate owner`);
this.get('crate.owner_user').removeObject(owner);
this.crate.owner_user.removeObject(owner);
break;
case 'team':
this.set('removed', `Team ${owner.get('display_name')} removed as crate owner`);
this.get('crate.owner_team').removeObject(owner);
this.crate.owner_team.removeObject(owner);
break;
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/crate/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class CrateVersionController extends Controller {

@computed('crate.owner_user', 'session.currentUser.id')
get isOwner() {
return this.get('crate.owner_user').findBy('id', this.get('session.currentUser.id'));
return this.crate.owner_user.findBy('id', this.session.currentUser?.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of these are async relationships?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, good question, some of them actually are 🤔

}

@readOnly('crate.versions') sortedVersions;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/crate/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class CrateVersionsController extends Controller {

@computed('model.owner_user', 'session.currentUser.id')
get isOwner() {
return this.get('model.owner_user').findBy('id', this.get('session.currentUser.id'));
return this.model.owner_user.findBy('id', this.session.currentUser?.id);
}
}
4 changes: 2 additions & 2 deletions app/controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export default class DashboardController extends Controller {

@computed('myCrates.[]')
get hasMoreCrates() {
return this.get('myCrates.length') > TO_SHOW;
return this.myCrates.length > TO_SHOW;
}

@computed('myFollowing.[]')
get hasMoreFollowing() {
return this.get('myFollowing.length') > TO_SHOW;
return this.myFollowing.length > TO_SHOW;
}

@task(function* () {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class IndexController extends Controller {

@computed('dataTask.{lastSuccessful,isRunning}')
get hasData() {
return this.get('dataTask.lastSuccessful') && !this.get('dataTask.isRunning');
return this.dataTask.lastSuccessful && !this.dataTask.isRunning;
}

@(task(function* () {
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/me/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class MeIndexController extends Controller {
}

setAllEmailNotifications(value) {
this.get('ownedCrates').forEach(c => {
this.ownedCrates.forEach(c => {
c.set('email_notifications', value);
});
}
Expand All @@ -41,7 +41,7 @@ export default class MeIndexController extends Controller {
await ajax(`/api/v1/me/email_notifications`, {
method: 'PUT',
body: JSON.stringify(
this.get('ownedCrates').map(c => ({
this.ownedCrates.map(c => ({
id: parseInt(c.id, 10),
email_notifications: c.email_notifications,
})),
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default class SearchController extends Controller {

@computed('dataTask.{lastSuccessful,isRunning}')
get hasData() {
return this.get('dataTask.lastSuccessful') || !this.get('dataTask.isRunning');
return this.dataTask.lastSuccessful || !this.dataTask.isRunning;
}

@computed('dataTask.{lastSuccessful,isRunning}')
get firstResultPending() {
return !this.get('dataTask.lastSuccessful') && this.get('dataTask.isRunning');
return !this.dataTask.lastSuccessful && this.dataTask.isRunning;
}

@readOnly('model.meta.total') totalItems;
Expand Down
3 changes: 1 addition & 2 deletions app/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export default class Team extends Model {
org_name;

@computed('name', 'org_name', function () {
let { name, org_name } = this.getProperties('name', 'org_name');
return `${org_name}/${name}`;
return `${this.org_name}/${this.name}`;
})
display_name;
}
6 changes: 4 additions & 2 deletions app/models/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default class Version extends Model {
@alias('loadAuthorsTask.last.value') authorNames;

@(task(function* () {
let authors = yield this.get('authors');
// trigger the async relationship to load the content
let authors = yield this.authors;
return authors.meta.names;
}).keepLatest())
loadAuthorsTask;
Expand All @@ -39,7 +40,8 @@ export default class Version extends Model {
@alias('loadDepsTask.last.value.dev') devDependencies;

@(task(function* () {
let dependencies = yield this.get('dependencies');
// trigger the async relationship to load the content
let dependencies = yield this.dependencies;

let normal = dependencies.filterBy('kind', 'normal').uniqBy('crate_id');
let build = dependencies.filterBy('kind', 'build').uniqBy('crate_id');
Expand Down
2 changes: 1 addition & 1 deletion app/routes/me/crates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class MeCratesRoute extends AuthenticatedRoute {
};

model(params) {
params.user_id = this.get('session.currentUser.id');
params.user_id = this.session.currentUser.id;
return this.store.query('crate', params);
}
}