Skip to content

Commit f6eb314

Browse files
committed
Further removal of computeds
1 parent 06cbf0d commit f6eb314

3 files changed

Lines changed: 25 additions & 45 deletions

File tree

app/controllers/project-version.js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
/* eslint-disable ember/no-computed-properties-in-native-classes */
2-
import { action, computed, set } from '@ember/object';
1+
import { action } from '@ember/object';
32
import { service } from '@ember/service';
4-
import { readOnly, alias } from '@ember/object/computed';
53
import Controller from '@ember/controller';
6-
import { A } from '@ember/array';
74
import values from 'lodash.values';
85
import groupBy from 'lodash.groupby';
96
import semverCompare from 'semver-compare';
@@ -25,35 +22,30 @@ export default class ProjectVersionController extends Controller {
2522
@service router;
2623
@service('project') projectService;
2724

28-
@alias('filterData.sideNav.showPrivate')
29-
showPrivateClasses;
25+
get showPrivateClasses() {
26+
return this.filterData.showPrivateClasses;
27+
}
3028

31-
@computed('model')
3229
get classesIDs() {
3330
return this.getRelationshipIDs('classes');
3431
}
3532

36-
@computed('model')
3733
get publicClassesIDs() {
3834
return this.getRelationshipIDs('public-classes');
3935
}
4036

41-
@computed('model')
4237
get namespaceIDs() {
4338
return this.getRelationshipIDs('namespaces');
4439
}
4540

46-
@computed('model')
4741
get publicNamespaceIDs() {
4842
return this.getRelationshipIDs('public-namespaces');
4943
}
5044

51-
@computed('model.id')
5245
get moduleIDs() {
5346
return this.getModuleRelationships(this.model.id, 'modules');
5447
}
5548

56-
@computed('model.id')
5749
get publicModuleIDs() {
5850
return this.getModuleRelationships(this.model.id, 'public-modules');
5951
}
@@ -73,30 +65,25 @@ export default class ProjectVersionController extends Controller {
7365
getRelationshipIDs(relationship) {
7466
const projectId = this.model.project.id;
7567
const classes = this.model.hasMany(relationship);
76-
const sorted = A(classes.ids()).sort();
68+
const sorted = Array.from(classes.ids()).sort();
7769
//ids come in as ember-2.16.0-@ember/object/promise-proxy-mixin or ember-4.12.0-alpha.23-@ember/object/promise-proxy-mixin
7870
//so we remove the project name and version (including pre-release) to get the class name
79-
return A(sorted)
80-
.toArray()
81-
.map((id) => {
82-
// Remove project name prefix
83-
const withoutProject = id.replace(`${projectId}-`, '');
84-
// Remove version (e.g., 2.16.0 or 4.12.0-alpha.23) and the following dash
85-
return withoutProject.replace(/^\d+\.\d+\.\d+(?:-[a-z]+\.\d+)?-/i, '');
86-
});
71+
return sorted.map((id) => {
72+
// Remove project name prefix
73+
const withoutProject = id.replace(`${projectId}-`, '');
74+
// Remove version (e.g., 2.16.0 or 4.12.0-alpha.23) and the following dash
75+
return withoutProject.replace(/^\d+\.\d+\.\d+(?:-[a-z]+\.\d+)?-/i, '');
76+
});
8777
}
8878

89-
@computed('showPrivateClasses', 'classesIDs', 'publicClassesIDs')
9079
get shownClassesIDs() {
9180
return this.showPrivateClasses ? this.classesIDs : this.publicClassesIDs;
9281
}
9382

94-
@computed('showPrivateClasses', 'moduleIDs', 'publicModuleIDs')
9583
get shownModuleIDs() {
9684
return this.showPrivateClasses ? this.moduleIDs : this.publicModuleIDs;
9785
}
9886

99-
@computed('showPrivateClasses', 'namespaceIDs', 'publicNamespaceIDs')
10087
get shownNamespaceIDs() {
10188
return this.showPrivateClasses
10289
? this.namespaceIDs
@@ -120,20 +107,21 @@ export default class ProjectVersionController extends Controller {
120107
return values(groupedVersions).map((groupedVersion) => groupedVersion[0]);
121108
}
122109

123-
@alias('project.urlVersion')
124-
urlVersion;
110+
get urlVersion() {
111+
return this.projectService.getUrlVersion();
112+
}
125113

126-
@computed('projectVersions.[]', 'model.version')
127114
get selectedProjectVersion() {
128115
return this.projectVersions.filter((pV) => pV.id === this.model.version)[0];
129116
}
130117

131-
@readOnly('model.project.id')
132-
activeProject;
118+
get activeProject() {
119+
return this.model.project.id;
120+
}
133121

134122
@action
135123
togglePrivateClasses() {
136-
set(this, 'showPrivateClasses', !this.showPrivateClasses);
124+
this.filterData.togglePrivateClasses();
137125
}
138126

139127
@action

app/controllers/project-version/modules/module.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
2-
import { computed } from '@ember/object';
31
import { service } from '@ember/service';
4-
// eslint-disable-next-line ember/no-computed-properties-in-native-classes
5-
import { alias } from '@ember/object/computed';
62
import ClassController from '../classes/class';
73
import uniq from 'lodash.uniq';
84
import union from 'lodash.union';
@@ -11,33 +7,29 @@ export default class ModuleController extends ClassController {
117
@service
128
filterData;
139

14-
@alias('filterData.sideNav.showPrivate')
15-
showPrivateClasses;
10+
get showPrivateClasses() {
11+
return this.filterData.showPrivateClasses;
12+
}
1613

17-
@computed('model.submodules')
1814
get submodules() {
1915
return Object.keys(this.model.submodules);
2016
}
2117

22-
@computed('model.namespaces')
2318
get namespaces() {
2419
return Object.keys(this.model.namespaces);
2520
}
2621

27-
@computed('model.{privateclasses,publicclasses}', 'showPrivateClasses')
2822
get classes() {
2923
if (this.showPrivateClasses) {
3024
return this.model.publicclasses.concat(this.model.privateclasses);
3125
}
3226
return this.model.publicclasses;
3327
}
3428

35-
@computed('classes', 'namespaces')
3629
get classesAndNamespaces() {
3730
return uniq(union(this.namespaces, this.classes).sort(), true);
3831
}
3932

40-
@computed('model.{allstaticfunctions,staticfunctions}', 'showPrivateClasses')
4133
get functionHeadings() {
4234
if (this.model.allstaticfunctions && this.showPrivateClasses) {
4335
return Object.keys(this.model.allstaticfunctions).sort();
@@ -47,7 +39,6 @@ export default class ModuleController extends ClassController {
4739
return {};
4840
}
4941

50-
@computed('model.{allstaticfunctions,staticfunctions}', 'showPrivateClasses')
5142
get functions() {
5243
if (this.showPrivateClasses && this.model.allstaticfunctions) {
5344
return this.model.allstaticfunctions;

app/services/filter-data.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export default class FilterDataService extends Service {
66
@tracked showProtected = false;
77
@tracked showPrivate = false;
88
@tracked showDeprecated = false;
9+
@tracked showPrivateClasses = false;
910

10-
sideNav = {
11-
showPrivate: false,
12-
};
11+
togglePrivateClasses() {
12+
this.showPrivateClasses = !this.showPrivateClasses;
13+
}
1314
}

0 commit comments

Comments
 (0)