Skip to content

Commit 7eb7967

Browse files
HuggableSquaretoddjordan
authored andcommitted
Fix anchor scrolling by making sure all data is loaded before render
1 parent a07e779 commit 7eb7967

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

app/routes/application.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getCompactVersion from 'ember-api-docs/utils/get-compact-version';
66

77
export default Route.extend({
88
headData: service(),
9+
legacyModuleMappings: service(),
910

1011
title(tokens) {
1112
let [version, entity] = tokens;
@@ -20,8 +21,9 @@ export default Route.extend({
2021
}
2122
return '';
2223
},
23-
afterModel() {
24+
async afterModel() {
2425
set(this, 'headData.cdnDomain', ENV.API_HOST);
26+
await this.get('legacyModuleMappings').initMappings();
2527
return this._super(...arguments);
2628
}
2729

app/services/legacy-module-mappings.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fetch from 'fetch';
2-
import { task } from 'ember-concurrency';
32
import config from 'ember-api-docs/config/environment';
43
import Service from '@ember/service';
54

@@ -11,20 +10,16 @@ const LOCALNAME_CONVERSIONS = {
1110

1211
export default Service.extend({
1312

14-
init() {
15-
this.get('initMappings').perform();
16-
},
17-
18-
initMappings: task(function * () {
13+
async initMappings() {
1914
try {
20-
let response = yield this.fetch();
21-
let mappings = yield response.json();
15+
let response = await this.fetch();
16+
let mappings = await response.json();
2217
let newMappings = this.buildMappings(mappings);
2318
this.set('mappings', newMappings);
2419
} catch (e) {
2520
this.set('mappings', []);
2621
}
27-
}),
22+
},
2823

2924
buildMappings(mappings) {
3025
return mappings.map(item => {
@@ -41,7 +36,7 @@ export default Service.extend({
4136
},
4237

4338
getModule(name, documentedModule) {
44-
if (!this.get('initMappings.isIdle')) {
39+
if (!this.mappings) {
4540
return '';
4641
}
4742
let matches = this.mappings.filter(element => element.localName === name);
@@ -88,15 +83,15 @@ export default Service.extend({
8883

8984

9085
hasFunctionMapping(name, module) {
91-
if (!this.get('initMappings.isIdle')) {
86+
if (!this.mappings) {
9287
return false;
9388
}
9489
let filtered = this.mappings.filter(element => element.export === name && element.module === module);
9590
return filtered.length > 0;
9691
},
9792

9893
hasClassMapping(name) {
99-
if (!this.get('initMappings.isIdle')) {
94+
if (!this.mappings) {
10095
return false;
10196
}
10297
return this.mappings.filter(element => element.localName === name).length > 0;

app/templates/components/class-field-description.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@
3232
</a>
3333
{{/if}}
3434
</p>
35-
{{#if legacyModuleMappings.initMappings.isIdle}}
36-
{{#if (and (eq field.static 1) (eq field.itemtype "method") hasImportExample)}}
37-
{{import-example item=(concat "{ " field.name " }") package=field.class}}
38-
{{/if}}
35+
{{#if (and (eq field.static 1) (eq field.itemtype "method") hasImportExample)}}
36+
{{import-example item=(concat "{ " field.name " }") package=field.class}}
3937
{{/if}}
4038
<dl class="parameters">
4139
{{#each field.params as |param|}}

app/templates/project-version/classes/class.hbs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636
</div>
3737
{{/if}}
3838
</div>
39-
{{#if (and (not (eq static 1)) legacyModuleMappings.initMappings.isIdle)}}
40-
{{#if hasImportExample}}
41-
{{import-example item=model.name package=module}}
42-
{{/if}}
39+
{{#if (and (not (eq static 1)) hasImportExample)}}
40+
{{import-example item=model.name package=module}}
4341
{{/if}}
4442
<p class="description">{{html-safe model.description}}</p>
4543

0 commit comments

Comments
 (0)