Skip to content

Commit 158381f

Browse files
jenwebermansona
andcommitted
Refactor head data service
Co-authored-by: Chris Manson <[email protected]>
1 parent 6504f1e commit 158381f

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

app/routes/project-version.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class ProjectVersionRoute extends Route {
2424
projectService;
2525

2626
titleToken(model) {
27-
return model.get('version');
27+
return model.version;
2828
}
2929

3030
async model({ project, project_version }) {
@@ -68,8 +68,7 @@ export default class ProjectVersionRoute extends Route {
6868
);
6969
let isLatestVersion =
7070
transitionVersion === latestVersion || transitionVersion === 'release';
71-
let shouldConvertPackages =
72-
semverCompare(model.get('version'), '2.16') < 0;
71+
let shouldConvertPackages = semverCompare(model.version, '2.16') < 0;
7372
if (!shouldConvertPackages || isLatestVersion) {
7473
// ... and the transition version is the latest release,
7574
// display the landing page at
@@ -111,17 +110,17 @@ export default class ProjectVersionRoute extends Route {
111110
}
112111

113112
_gatherHeadDataFromVersion(model, projectVersion) {
114-
this.set('headData.isRelease', projectVersion === 'release');
115-
this.set('headData.compactVersion', model.get('compactVersion'));
116-
this.set('headData.urlVersion', projectVersion);
117-
if (!this.get('headData.isRelease')) {
118-
let request = this.get('fastboot.request');
119-
let href = this.get('fastboot.isFastBoot')
113+
this.headData.isRelease = projectVersion === 'release';
114+
this.headData.compactVersion = model.get('compactVersion');
115+
this.headData.urlVersion = projectVersion;
116+
if (!this.headData.isRelease) {
117+
let request = this.fastboot.request;
118+
let href = this.fastboot.isFastBoot
120119
? `${config.APP.domain}/${request.path}`
121120
: window.location.href;
122121
let version = new RegExp(model.get('compactVersion'), 'g');
123122
let canonicalUrl = href.replace(version, 'release');
124-
this.set('headData.canonicalUrl', canonicalUrl);
123+
this.headData.canonicalUrl = canonicalUrl;
125124
}
126125
}
127126

@@ -215,7 +214,7 @@ export default class ProjectVersionRoute extends Route {
215214
// to the home page instead of trying to translate the url
216215
let shouldConvertPackages = this.shouldConvertPackages(
217216
ver,
218-
this.get('projectService.version')
217+
this.projectService.version
219218
);
220219
let isEmberProject = project === 'ember';
221220
if (!isEmberProject || !shouldConvertPackages) {
@@ -246,7 +245,7 @@ export default class ProjectVersionRoute extends Route {
246245
let encodedModule = moduleRevs[0]
247246
.split('-')
248247
.reduce((result, val, index, arry) => {
249-
if (val === this.get('projectService.version')) {
248+
if (val === this.projectService.version) {
250249
return arry.slice(index + 1).join('-');
251250
}
252251
return result;

app/services/head-data.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Service from '@ember/service';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
export default class HeadDataService extends Service {
5+
@tracked title;
6+
@tracked isRelease;
7+
@tracked compactVersion;
8+
@tracked urlVersion;
9+
@tracked canonicalUrl;
10+
@tracked description;
11+
@tracked cdnDomain;
12+
}

tests/unit/services/head-data-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Service | head-data', function(hooks) {
5+
setupTest(hooks);
6+
7+
// TODO: Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let service = this.owner.lookup('service:head-data');
10+
assert.ok(service);
11+
});
12+
});

0 commit comments

Comments
 (0)