Skip to content

Commit c93ef34

Browse files
authored
ember-data: Fix ember-data:deprecate-array-like warning (#10173)
Since the underlying implementation of `@reads` uses `.get()`, which introduces deprecation warnings `deprecation id: ember-data:deprecate-array-like`, this commit fixes the warning by rewriting the `@reads('some.deep.path')` to equivalent `@cached get function ()`.
1 parent 8e725c4 commit c93ef34

File tree

11 files changed

+44
-41
lines changed

11 files changed

+44
-41
lines changed

app/controllers/categories.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../utils/pagination';
75

86
export default class CategoriesController extends Controller {
@@ -11,11 +9,13 @@ export default class CategoriesController extends Controller {
119
@tracked per_page = 100;
1210
@tracked sort = 'alpha';
1311

14-
@reads('model.meta.total') totalItems;
15-
1612
@pagination() pagination;
1713

1814
get currentSortBy() {
1915
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
2016
}
17+
18+
get totalItems() {
19+
return this.model.meta.total ?? 0;
20+
}
2121
}

app/controllers/category/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../../utils/pagination';
75

86
export default class CategoryIndexController extends Controller {
@@ -11,8 +9,6 @@ export default class CategoryIndexController extends Controller {
119
@tracked per_page = 10;
1210
@tracked sort = 'recent-downloads';
1311

14-
@reads('model.meta.total') totalItems;
15-
1612
@pagination() pagination;
1713

1814
category = null;
@@ -30,4 +26,8 @@ export default class CategoryIndexController extends Controller {
3026
return 'Recent Downloads';
3127
}
3228
}
29+
30+
get totalItems() {
31+
return this.model.meta.total ?? 0;
32+
}
3333
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../../utils/pagination';
75

86
export default class ReverseDependenciesController extends Controller {
@@ -11,7 +9,9 @@ export default class ReverseDependenciesController extends Controller {
119
@tracked per_page = 10;
1210
@tracked crate = null;
1311

14-
@reads('model.meta.total') totalItems;
15-
1612
@pagination() pagination;
13+
14+
get totalItems() {
15+
return this.model.meta.total ?? 0;
16+
}
1717
}

app/controllers/crates.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../utils/pagination';
75

86
export default class CratesController extends Controller {
@@ -11,7 +9,6 @@ export default class CratesController extends Controller {
119
@tracked per_page = 50;
1210
@tracked sort = 'recent-downloads';
1311

14-
@reads('model.meta.total') totalItems;
1512
@pagination() pagination;
1613

1714
get currentSortBy() {
@@ -27,4 +24,8 @@ export default class CratesController extends Controller {
2724
return 'Alphabetical';
2825
}
2926
}
27+
28+
get totalItems() {
29+
return this.model.meta.total ?? 0;
30+
}
3031
}

app/controllers/keyword.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../utils/pagination';
75

86
export default class KeywordIndexController extends Controller {
@@ -11,8 +9,6 @@ export default class KeywordIndexController extends Controller {
119
@tracked per_page = 10;
1210
@tracked sort = 'recent-downloads';
1311

14-
@reads('model.crates.meta.total') totalItems;
15-
1612
@pagination() pagination;
1713

1814
get currentSortBy() {
@@ -28,4 +24,8 @@ export default class KeywordIndexController extends Controller {
2824
return 'Recent Downloads';
2925
}
3026
}
27+
28+
get totalItems() {
29+
return this.model.crates.meta.total ?? 0;
30+
}
3131
}

app/controllers/keywords.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../utils/pagination';
75

86
export default class KeywordsController extends Controller {
@@ -11,11 +9,13 @@ export default class KeywordsController extends Controller {
119
@tracked per_page = 10;
1210
@tracked sort = 'crates';
1311

14-
@reads('model.meta.total') totalItems;
15-
1612
@pagination() pagination;
1713

1814
get currentSortBy() {
1915
return this.sort === 'crates' ? '# Crates' : 'Alphabetical';
2016
}
17+
18+
get totalItems() {
19+
return this.model.meta.total ?? 0;
20+
}
2121
}

app/controllers/me/crates.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../../utils/pagination';
75

86
// TODO: reduce duplicatoin with controllers/crates
@@ -13,8 +11,6 @@ export default class MeCratesController extends Controller {
1311
@tracked per_page = 10;
1412
@tracked sort = 'alpha';
1513

16-
@reads('model.meta.total') totalItems;
17-
1814
@pagination() pagination;
1915

2016
get currentSortBy() {
@@ -30,4 +26,8 @@ export default class MeCratesController extends Controller {
3026
return 'Alphabetical';
3127
}
3228
}
29+
30+
get totalItems() {
31+
return this.model.meta.total ?? 0;
32+
}
3333
}

app/controllers/me/following.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../../utils/pagination';
75

86
// TODO: reduce duplicatoin with controllers/me/crates
@@ -13,11 +11,13 @@ export default class FollowingController extends Controller {
1311
@tracked per_page = 10;
1412
@tracked sort = 'alpha';
1513

16-
@reads('model.meta.total') totalItems;
17-
1814
@pagination() pagination;
1915

2016
get currentSortBy() {
2117
return this.sort === 'downloads' ? 'Downloads' : 'Alphabetical';
2218
}
19+
20+
get totalItems() {
21+
return this.model.meta.total ?? 0;
22+
}
2323
}

app/controllers/search.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ export default class SearchController extends Controller {
2929
return !this.dataTask.lastComplete && this.dataTask.isRunning;
3030
}
3131

32-
@reads('model.meta.total') totalItems;
33-
3432
@pagination() pagination;
3533

3634
get pageTitle() {
@@ -75,4 +73,8 @@ export default class SearchController extends Controller {
7573

7674
return await this.store.query('crate', searchOptions);
7775
});
76+
77+
get totalItems() {
78+
return this.model.meta.total ?? 0;
79+
}
7880
}

app/controllers/team.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Controller from '@ember/controller';
22
import { tracked } from '@glimmer/tracking';
33

4-
import { reads } from 'macro-decorators';
5-
64
import { pagination } from '../utils/pagination';
75

86
export default class TeamController extends Controller {
@@ -11,8 +9,6 @@ export default class TeamController extends Controller {
119
@tracked per_page = 10;
1210
@tracked sort = 'alpha';
1311

14-
@reads('model.crates.meta.total') totalItems;
15-
1612
@pagination() pagination;
1713

1814
get currentSortBy() {
@@ -28,4 +24,8 @@ export default class TeamController extends Controller {
2824
return 'Alphabetical';
2925
}
3026
}
27+
28+
get totalItems() {
29+
return this.model.crates.meta.total ?? 0;
30+
}
3131
}

0 commit comments

Comments
 (0)