Skip to content

Commit 1f47443

Browse files
Modernize legacy module mapping service
1 parent 0a4ebbe commit 1f47443

File tree

4 files changed

+44
-74
lines changed

4 files changed

+44
-74
lines changed

app/routes/application.js

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

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

1110
title(tokens) {
1211
let [version, entity] = tokens;
1312
if (!entity) {
1413
entity = 'Ember';
1514
}
15+
1616
if (version) {
1717
const compactVersion = getCompactVersion(version);
1818
const title = `${[entity, compactVersion].join(' - ')} - Ember API Documentation`;
@@ -21,10 +21,9 @@ export default Route.extend({
2121
}
2222
return '';
2323
},
24+
2425
async afterModel() {
2526
set(this, 'headData.cdnDomain', ENV.API_HOST);
26-
await this.legacyModuleMappings.initMappings();
2727
return this._super(...arguments);
2828
}
29-
3029
});
Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,82 @@
1-
import fetch from 'fetch';
21
import Service from '@ember/service';
2+
import rfcMappings from 'ember-rfc176-data';
3+
import { computed } from '@ember/object';
34

4-
const LOCALNAME_CONVERSIONS = {
5+
const LOCAL_NAME_CONVERSIONS = {
56
Object: 'EmberObject',
67
Array: 'EmberArray',
78
Error: 'EmberError'
89
};
910

1011
export default Service.extend({
11-
12-
async initMappings() {
12+
mappings: computed(function() {
1313
try {
14-
let response = await this.fetch();
15-
let mappings = await response.json();
16-
let newMappings = this.buildMappings(mappings);
17-
this.set('mappings', newMappings);
14+
return rfcMappings.map(item => {
15+
let newItem = Object.assign({}, item);
16+
if (LOCAL_NAME_CONVERSIONS[newItem.localName]) {
17+
newItem.localName = LOCAL_NAME_CONVERSIONS[newItem.localName];
18+
}
19+
return newItem;
20+
});
1821
} catch (e) {
19-
this.set('mappings', []);
22+
return [];
2023
}
21-
},
22-
23-
buildMappings(mappings) {
24-
return mappings.map(item => {
25-
let newItem = Object.assign({}, item);
26-
if (LOCALNAME_CONVERSIONS[newItem.localName]) {
27-
newItem.localName = LOCALNAME_CONVERSIONS[newItem.localName];
28-
}
29-
return newItem;
30-
});
31-
},
32-
33-
fetch() {
34-
return fetch('/assets/mappings.json');
35-
},
24+
}),
3625

3726
getModule(name, documentedModule) {
3827
if (!this.mappings) {
3928
return '';
4029
}
41-
let matches = this.mappings.filter(element => element.localName === name);
42-
return matches.length > 0 ? matches[0].module : documentedModule;
30+
31+
let match = this.mappings.find(element => element.localName === name);
32+
return match ? match.module : documentedModule;
4333
},
4434

4535
getNewClassFromOld(oldClassName, mappings) {
46-
let matches = mappings.filter(element => element.global === oldClassName);
47-
if (matches.length > 0) {
48-
if (matches[0].localName) {
36+
let match = mappings.find(element => element.global === oldClassName);
37+
38+
if (match) {
39+
if (match.localName) {
4940
return {
5041
itemType: 'class',
51-
newModule: matches[0].module,
52-
newName: matches[0].localName
53-
}
42+
newModule: match.module,
43+
newName: match.localName
44+
};
5445
} else {
5546
return {
5647
itemType: 'function',
57-
newModule: matches[0].module,
58-
newName: matches[0].export
59-
}
48+
newModule: match.module,
49+
newName: match.export
50+
};
6051
}
61-
6252
} else {
6353
return {
6454
itemType: 'class',
6555
newName: oldClassName
66-
}
56+
};
6757
}
6858
},
6959

7060
getNewModuleFromOld(oldModuleName, mappings) {
71-
let matches = mappings.filter(element => element.module === oldModuleName);
72-
if (matches.length > 0) {
73-
return {
74-
module: matches[0].replacement.module
75-
};
76-
} else {
77-
return {
78-
module: oldModuleName
79-
};
80-
}
61+
let match = mappings.find(element => element.module === oldModuleName);
62+
return { module: match ? match.replacement.module : oldModuleName };
8163
},
8264

83-
84-
hasFunctionMapping(name, module) {
65+
hasFunctionMapping(name, moduleName) {
8566
if (!this.mappings) {
8667
return false;
8768
}
88-
let filtered = this.mappings.filter(element => element.export === name && element.module === module);
89-
return filtered.length > 0;
69+
70+
return Boolean(
71+
this.mappings.find(element => element.export === name && element.module === moduleName)
72+
);
9073
},
9174

9275
hasClassMapping(name) {
9376
if (!this.mappings) {
9477
return false;
9578
}
96-
return this.mappings.filter(element => element.localName === name).length > 0;
97-
}
9879

80+
return Boolean(this.mappings.find(element => element.localName === name));
81+
}
9982
});

ember-cli-build.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
22

33
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
4-
const Funnel = require('broccoli-funnel');
5-
const mergeTrees = require('broccoli-merge-trees');
64

75
module.exports = function(defaults) {
86
let app = new EmberApp(defaults, {
@@ -11,10 +9,7 @@ module.exports = function(defaults) {
119
generateAssetMap: true
1210
},
1311
sassOptions: {
14-
includePaths: [
15-
'app/styles',
16-
'node_modules/normalize.css'
17-
]
12+
includePaths: ['app/styles', 'node_modules/normalize.css']
1813
},
1914
autoprefixer: {
2015
overrideBrowsersList: ['default']
@@ -23,20 +18,15 @@ module.exports = function(defaults) {
2318
only: ['join', 'map-by']
2419
},
2520
'asset-cache': {
26-
version: '4', //Might have to change this with the app build,
21+
version: '4' //Might have to change this with the app build,
2722
},
2823
svgJar: {
2924
sourceDirs: ['public/assets/images']
3025
},
3126
'ember-cli-babel': {
32-
includePolyfill: true,
33-
},
27+
includePolyfill: true
28+
}
3429
});
3530

36-
let mappingsTree = new Funnel('node_modules/ember-rfc176-data/', {
37-
srcDir: '/',
38-
include: ['mappings.json'],
39-
destDir: '/assets/'
40-
});
41-
return mergeTrees([app.toTree(), mappingsTree]);
31+
return app.toTree();
4232
};

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"bourbon": "5.1.0",
2525
"ember-cli-browserstack": "^1.0.1",
26-
"ember-rfc176-data": "^0.3.5",
26+
"ember-rfc176-data": "^0.3.12",
2727
"express-sslify": "^1.2.0",
2828
"lodash.groupby": "^4.6.0",
2929
"lodash.last": "^3.0.0",
@@ -40,8 +40,6 @@
4040
"@ember/optional-features": "^0.6.3",
4141
"algoliasearch": "^3.32.1",
4242
"broccoli-asset-rev": "^3.0.0",
43-
"broccoli-funnel": "^2.0.1",
44-
"broccoli-merge-trees": "^2.0.0",
4543
"ember-a11y-testing": "^0.5.4",
4644
"ember-anchor": "~0.2.0",
4745
"ember-auto-import": "^1.2.21",

0 commit comments

Comments
 (0)