Skip to content

Commit e4ef88e

Browse files
committed
Auto merge of #4068 - Turbo87:macros, r=Mikek2252
Replace computed properties with `macro-decorators` see https://pzuraq.github.io/macro-decorators/ This has basically the same API as ``@ember/object/computed`` but relies on tracked properties underneath, which should result in a small performance improvement.
2 parents f6b3d4f + c9ef47c commit e4ef88e

File tree

25 files changed

+107
-114
lines changed

25 files changed

+107
-114
lines changed

app/components/crate-header.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { computed } from '@ember/object';
21
import { inject as service } from '@ember/service';
32
import Component from '@glimmer/component';
43

54
export default class CrateHeader extends Component {
65
@service session;
76

8-
@computed('args.crate.owner_user', 'session.currentUser.id')
97
get isOwner() {
108
return this.args.crate.owner_user.findBy('id', this.session.currentUser?.id);
119
}

app/components/settings/api-tokens.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { action } from '@ember/object';
2-
import { sort } from '@ember/object/computed';
32
import { inject as service } from '@ember/service';
43
import Component from '@glimmer/component';
54
import { tracked } from '@glimmer/tracking';
65

76
import { task } from 'ember-concurrency';
7+
import { sortBy } from 'macro-decorators';
88

99
export default class ApiTokens extends Component {
1010
@service store;
1111
@service notifications;
1212

1313
@tracked newToken;
1414

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

1817
@action startNewToken() {
1918
this.newToken = this.store.createRecord('api-token');

app/components/version-list/row.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { action, computed } from '@ember/object';
1+
import { action } from '@ember/object';
22
import { inject as service } from '@ember/service';
33
import Component from '@glimmer/component';
44
import { tracked } from '@glimmer/tracking';
@@ -37,7 +37,6 @@ export default class VersionRow extends Component {
3737
return title;
3838
}
3939

40-
@computed('args.version.crate.owner_user', 'session.currentUser.id')
4140
get isOwner() {
4241
return this.args.version.crate?.owner_user?.findBy('id', this.session.currentUser?.id);
4342
}

app/controllers/categories.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

78
export default class CategoriesController extends Controller {
89
queryParams = ['page', 'per_page', 'sort'];
9-
page = '1';
10-
per_page = 100;
11-
sort = 'alpha';
10+
@tracked page = '1';
11+
@tracked per_page = 100;
12+
@tracked sort = 'alpha';
1213

13-
@readOnly('model.meta.total') totalItems;
14+
@reads('model.meta.total') totalItems;
1415

1516
@pagination() pagination;
1617

17-
@computed('sort')
1818
get currentSortBy() {
1919
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
2020
}

app/controllers/category/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

78
export default class CategoryIndexController extends Controller {
89
queryParams = ['page', 'per_page', 'sort'];
9-
page = '1';
10-
per_page = 10;
11-
sort = 'recent-downloads';
10+
@tracked page = '1';
11+
@tracked per_page = 10;
12+
@tracked sort = 'recent-downloads';
1213

13-
@readOnly('model.meta.total') totalItems;
14+
@reads('model.meta.total') totalItems;
1415

1516
@pagination() pagination;
1617

1718
category = null;
1819

19-
@computed('sort')
2020
get currentSortBy() {
2121
if (this.sort === 'downloads') {
2222
return 'All-Time Downloads';
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import Controller from '@ember/controller';
2-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
35

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

68
export default class ReverseDependenciesController extends Controller {
79
queryParams = ['page', 'per_page'];
8-
page = '1';
9-
per_page = 10;
10-
crate = null;
10+
@tracked page = '1';
11+
@tracked per_page = 10;
12+
@tracked crate = null;
1113

12-
@readOnly('model.meta.total') totalItems;
14+
@reads('model.meta.total') totalItems;
1315

1416
@pagination() pagination;
1517
}

app/controllers/crate/version.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { alias } from '@ember/object/computed';
42
import { inject as service } from '@ember/service';
53

64
import { task } from 'ember-concurrency';
5+
import { alias } from 'macro-decorators';
76

87
export default class CrateVersionController extends Controller {
98
@service session;
109

11-
@computed('requestedVersion', 'currentVersion', 'crate')
1210
get downloadsContext() {
1311
return this.requestedVersion ? this.currentVersion : this.crate;
1412
}
@@ -18,7 +16,6 @@ export default class CrateVersionController extends Controller {
1816
@alias('model.requestedVersion') requestedVersion;
1917
@alias('model.version') currentVersion;
2018

21-
@computed('crate.owner_user', 'session.currentUser.id')
2219
get isOwner() {
2320
return this.crate.owner_user.findBy('id', this.session.currentUser?.id);
2421
}

app/controllers/crates.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import Controller from '@ember/controller';
2-
import { action, computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { action } from '@ember/object';
3+
import { tracked } from '@glimmer/tracking';
4+
5+
import { reads } from 'macro-decorators';
46

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

79
export default class CratesController extends Controller {
810
queryParams = ['letter', 'page', 'per_page', 'sort'];
9-
letter = null;
10-
page = '1';
11-
per_page = 50;
12-
sort = 'alpha';
11+
@tracked letter = null;
12+
@tracked page = '1';
13+
@tracked per_page = 50;
14+
@tracked sort = 'alpha';
1315
alphabet = [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'];
1416

15-
@readOnly('model.meta.total') totalItems;
17+
@reads('model.meta.total') totalItems;
1618
@pagination() pagination;
1719

18-
@computed('sort')
1920
get currentSortBy() {
2021
if (this.sort === 'downloads') {
2122
return 'All-Time Downloads';

app/controllers/dashboard.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { A } from '@ember/array';
22
import Controller from '@ember/controller';
3-
import { computed } from '@ember/object';
4-
import { alias } from '@ember/object/computed';
53

64
import { task } from 'ember-concurrency';
5+
import { alias } from 'macro-decorators';
76

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

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

20-
@computed('myCrates.[]')
2119
get visibleCrates() {
2220
return this.myCrates.slice(0, TO_SHOW);
2321
}
2422

25-
@computed('myFollowing.[]')
2623
get visibleFollowing() {
2724
return this.myFollowing.slice(0, TO_SHOW);
2825
}
2926

30-
@computed('myCrates.[]')
3127
get hasMoreCrates() {
3228
return this.myCrates.length > TO_SHOW;
3329
}
3430

35-
@computed('myFollowing.[]')
3631
get hasMoreFollowing() {
3732
return this.myFollowing.length > TO_SHOW;
3833
}

app/controllers/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import Controller from '@ember/controller';
2-
import { action, computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { action } from '@ember/object';
43
import { inject as service } from '@ember/service';
54

65
import { task } from 'ember-concurrency';
6+
import { reads } from 'macro-decorators';
77

88
export default class IndexController extends Controller {
99
@service fetcher;
1010

11-
@readOnly('dataTask.lastSuccessful.value') model;
11+
@reads('dataTask.lastSuccessful.value') model;
1212

13-
@computed('dataTask.{lastSuccessful,isRunning}')
1413
get hasData() {
1514
return this.dataTask.lastSuccessful && !this.dataTask.isRunning;
1615
}

app/controllers/keyword/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

78
export default class KeywordIndexController extends Controller {
89
queryParams = ['page', 'per_page', 'sort'];
9-
page = '1';
10-
per_page = 10;
11-
sort = 'recent-downloads';
10+
@tracked page = '1';
11+
@tracked per_page = 10;
12+
@tracked sort = 'recent-downloads';
1213

13-
@readOnly('model.meta.total') totalItems;
14+
@reads('model.meta.total') totalItems;
1415

1516
@pagination() pagination;
1617

17-
@computed('sort')
1818
get currentSortBy() {
1919
if (this.sort === 'downloads') {
2020
return 'All-Time Downloads';

app/controllers/keywords.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

78
export default class KeywordsController extends Controller {
89
queryParams = ['page', 'per_page', 'sort'];
9-
page = '1';
10-
per_page = 10;
11-
sort = 'crates';
10+
@tracked page = '1';
11+
@tracked per_page = 10;
12+
@tracked sort = 'crates';
1213

13-
@readOnly('model.meta.total') totalItems;
14+
@reads('model.meta.total') totalItems;
1415

1516
@pagination() pagination;
1617

17-
@computed('sort')
1818
get currentSortBy() {
1919
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
2020
}

app/controllers/me/crates.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

78
// TODO: reduce duplicatoin with controllers/crates
89

910
export default class MeCratesController extends Controller {
1011
queryParams = ['page', 'per_page', 'sort'];
11-
page = '1';
12-
per_page = 10;
13-
sort = 'alpha';
12+
@tracked page = '1';
13+
@tracked per_page = 10;
14+
@tracked sort = 'alpha';
1415

15-
@readOnly('model.meta.total') totalItems;
16+
@reads('model.meta.total') totalItems;
1617

1718
@pagination() pagination;
1819

19-
@computed('sort')
2020
get currentSortBy() {
2121
if (this.sort === 'downloads') {
2222
return 'All-Time Downloads';

app/controllers/me/following.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import Controller from '@ember/controller';
2-
import { computed } from '@ember/object';
3-
import { readOnly } from '@ember/object/computed';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
import { reads } from 'macro-decorators';
45

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

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

910
export default class FollowingController extends Controller {
1011
queryParams = ['page', 'per_page', 'sort'];
11-
page = '1';
12-
per_page = 10;
13-
sort = 'alpha';
12+
@tracked page = '1';
13+
@tracked per_page = 10;
14+
@tracked sort = 'alpha';
1415

15-
@readOnly('model.meta.total') totalItems;
16+
@reads('model.meta.total') totalItems;
1617

1718
@pagination() pagination;
1819

19-
@computed('sort')
2020
get currentSortBy() {
2121
return this.sort === 'downloads' ? 'Downloads' : 'Alphabetical';
2222
}

app/controllers/me/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Controller from '@ember/controller';
2-
import { action, computed } from '@ember/object';
3-
import { alias } from '@ember/object/computed';
2+
import { action } from '@ember/object';
43
import Ember from 'ember';
54

5+
import { alias } from 'macro-decorators';
6+
67
import ajax from '../../utils/ajax';
78

89
export default class MeIndexController extends Controller {
@@ -13,7 +14,6 @@ export default class MeIndexController extends Controller {
1314
emailNotificationsError = false;
1415
emailNotificationsSuccess = false;
1516

16-
@computed
1717
get hasEmailNotificationFeature() {
1818
return Ember.testing;
1919
}

0 commit comments

Comments
 (0)