Skip to content

Replace computed properties with macro-decorators #4068

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 24 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87c8fb7
Add `macro-decorators` dependency
Turbo87 Oct 20, 2021
3637b8c
utils/pagination: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
f54b94f
reverse-dependencies: Use `macro-decorators` instead of computed prop…
Turbo87 Oct 20, 2021
e33473c
crate.version: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
2baec78
category.index: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
800911d
keyword.index: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
6bd349d
me.crates: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
caafe24
me.following: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
40928ca
me.index: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
cfcb1f7
categories: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
ad5b12c
crates: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
104283a
dashboard: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
0c3b709
index: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
d2354b6
keywords: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
7c6be25
search: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
48b182b
team: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
8e38860
user: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
f335bc9
services/session: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
eacff8d
services/playground: Use `macro-decorators` instead of computed prope…
Turbo87 Oct 20, 2021
6398a1e
model/version: Use `macro-decorators` instead of computed properties
Turbo87 Oct 20, 2021
7b1afb8
Settings::ApiTokens: Use `macro-decorators` instead of computed prope…
Turbo87 Oct 20, 2021
16d3a2e
VersionList::Row: Remove unnecessary `@computed` decorator
Turbo87 Oct 20, 2021
803a8bb
CrateHeader: Remove unnecessary `@computed` decorator
Turbo87 Oct 20, 2021
c9ef47c
dashboard: Remove unnecessary `@computed` decorator
Turbo87 Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/components/crate-header.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';

export default class CrateHeader extends Component {
@service session;

@computed('args.crate.owner_user', 'session.currentUser.id')
get isOwner() {
return this.args.crate.owner_user.findBy('id', this.session.currentUser?.id);
}
Expand Down
5 changes: 2 additions & 3 deletions app/components/settings/api-tokens.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { action } from '@ember/object';
import { sort } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

import { task } from 'ember-concurrency';
import { sortBy } from 'macro-decorators';

export default class ApiTokens extends Component {
@service store;
@service notifications;

@tracked newToken;

tokenSort = ['created_at:desc'];
@sort('args.tokens', 'tokenSort') sortedTokens;
@sortBy('args.tokens', 'created_at', false) sortedTokens;

@action startNewToken() {
this.newToken = this.store.createRecord('api-token');
Expand Down
3 changes: 1 addition & 2 deletions app/components/version-list/row.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { action, computed } from '@ember/object';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
Expand Down Expand Up @@ -37,7 +37,6 @@ export default class VersionRow extends Component {
return title;
}

@computed('args.version.crate.owner_user', 'session.currentUser.id')
get isOwner() {
return this.args.version.crate?.owner_user?.findBy('id', this.session.currentUser?.id);
}
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/categories.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../utils/pagination';

export default class CategoriesController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 100;
sort = 'alpha';
@tracked page = '1';
@tracked per_page = 100;
@tracked sort = 'alpha';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

@computed('sort')
get currentSortBy() {
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
}
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/category/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../../utils/pagination';

export default class CategoryIndexController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 10;
sort = 'recent-downloads';
@tracked page = '1';
@tracked per_page = 10;
@tracked sort = 'recent-downloads';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

category = null;

@computed('sort')
get currentSortBy() {
if (this.sort === 'downloads') {
return 'All-Time Downloads';
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/crate/reverse-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import Controller from '@ember/controller';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../../utils/pagination';

export default class ReverseDependenciesController extends Controller {
queryParams = ['page', 'per_page'];
page = '1';
per_page = 10;
crate = null;
@tracked page = '1';
@tracked per_page = 10;
@tracked crate = null;

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;
}
5 changes: 1 addition & 4 deletions app/controllers/crate/version.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';

import { task } from 'ember-concurrency';
import { alias } from 'macro-decorators';

export default class CrateVersionController extends Controller {
@service session;

@computed('requestedVersion', 'currentVersion', 'crate')
get downloadsContext() {
return this.requestedVersion ? this.currentVersion : this.crate;
}
Expand All @@ -18,7 +16,6 @@ export default class CrateVersionController extends Controller {
@alias('model.requestedVersion') requestedVersion;
@alias('model.version') currentVersion;

@computed('crate.owner_user', 'session.currentUser.id')
get isOwner() {
return this.crate.owner_user.findBy('id', this.session.currentUser?.id);
}
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/crates.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../utils/pagination';

export default class CratesController extends Controller {
queryParams = ['letter', 'page', 'per_page', 'sort'];
letter = null;
page = '1';
per_page = 50;
sort = 'alpha';
@tracked letter = null;
@tracked page = '1';
@tracked per_page = 50;
@tracked sort = 'alpha';
alphabet = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'];

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;
@pagination() pagination;

@computed('sort')
get currentSortBy() {
if (this.sort === 'downloads') {
return 'All-Time Downloads';
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { A } from '@ember/array';
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';

import { task } from 'ember-concurrency';
import { alias } from 'macro-decorators';

import ajax from '../utils/ajax';

Expand All @@ -17,22 +16,18 @@ export default class DashboardController extends Controller {
@alias('model.myFollowing') myFollowing;
@alias('model.myStats') myStats;

@computed('myCrates.[]')
get visibleCrates() {
return this.myCrates.slice(0, TO_SHOW);
}

@computed('myFollowing.[]')
get visibleFollowing() {
return this.myFollowing.slice(0, TO_SHOW);
}

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

@computed('myFollowing.[]')
get hasMoreFollowing() {
return this.myFollowing.length > TO_SHOW;
}
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';

import { task } from 'ember-concurrency';
import { reads } from 'macro-decorators';

export default class IndexController extends Controller {
@service fetcher;

@readOnly('dataTask.lastSuccessful.value') model;
@reads('dataTask.lastSuccessful.value') model;

@computed('dataTask.{lastSuccessful,isRunning}')
get hasData() {
return this.dataTask.lastSuccessful && !this.dataTask.isRunning;
}
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/keyword/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../../utils/pagination';

export default class KeywordIndexController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 10;
sort = 'recent-downloads';
@tracked page = '1';
@tracked per_page = 10;
@tracked sort = 'recent-downloads';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

@computed('sort')
get currentSortBy() {
if (this.sort === 'downloads') {
return 'All-Time Downloads';
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/keywords.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../utils/pagination';

export default class KeywordsController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 10;
sort = 'crates';
@tracked page = '1';
@tracked per_page = 10;
@tracked sort = 'crates';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

@computed('sort')
get currentSortBy() {
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
}
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/me/crates.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../../utils/pagination';

// TODO: reduce duplicatoin with controllers/crates

export default class MeCratesController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 10;
sort = 'alpha';
@tracked page = '1';
@tracked per_page = 10;
@tracked sort = 'alpha';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

@computed('sort')
get currentSortBy() {
if (this.sort === 'downloads') {
return 'All-Time Downloads';
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/me/following.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import { tracked } from '@glimmer/tracking';

import { reads } from 'macro-decorators';

import { pagination } from '../../utils/pagination';

// TODO: reduce duplicatoin with controllers/me/crates

export default class FollowingController extends Controller {
queryParams = ['page', 'per_page', 'sort'];
page = '1';
per_page = 10;
sort = 'alpha';
@tracked page = '1';
@tracked per_page = 10;
@tracked sort = 'alpha';

@readOnly('model.meta.total') totalItems;
@reads('model.meta.total') totalItems;

@pagination() pagination;

@computed('sort')
get currentSortBy() {
return this.sort === 'downloads' ? 'Downloads' : 'Alphabetical';
}
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/me/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { action } from '@ember/object';
import Ember from 'ember';

import { alias } from 'macro-decorators';

import ajax from '../../utils/ajax';

export default class MeIndexController extends Controller {
Expand All @@ -13,7 +14,6 @@ export default class MeIndexController extends Controller {
emailNotificationsError = false;
emailNotificationsSuccess = false;

@computed
get hasEmailNotificationFeature() {
return Ember.testing;
}
Expand Down
Loading