Skip to content

Commit

Permalink
stop requesting mappings over the network
Browse files Browse the repository at this point in the history
for some reason we're requesting the mappings.json file on every initial page load (and not cached in the shoebox). This is in the application afterModel hook so there is no chance that we will ever not make this request, so it's worth just backing the json into the JS bundle to save a request
  • Loading branch information
mansona committed Jul 23, 2024
1 parent a937223 commit cee135e
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 146 deletions.
20 changes: 7 additions & 13 deletions app/routes/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ export default class ClassRoute extends Route {
legacyModuleMappings;

model(params) {
return this.legacyModuleMappings
.fetch()
.then((response) => response.json())
.then((mappings) => {
let ret = {
mappings: this.legacyModuleMappings.buildMappings(mappings),
className: params['class'].substr(
0,
params['class'].lastIndexOf('.')
),
};
return ret;
});
let ret = {
mappings: this.legacyModuleMappings.buildMappings(
this.legacyModuleMappings.legacyMappings
),
className: params['class'].substr(0, params['class'].lastIndexOf('.')),
};
return ret;
}

redirect(model) {
Expand Down
18 changes: 6 additions & 12 deletions app/routes/data-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ export default class DataClassRoute extends Route {
legacyModuleMappings;

model(params) {
return this.legacyModuleMappings
.fetch()
.then((response) => response.json())
.then((mappings) => {
return {
mappings: this.legacyModuleMappings.buildMappings(mappings),
className: params['class'].substr(
0,
params['class'].lastIndexOf('.')
),
};
});
return {
mappings: this.legacyModuleMappings.buildMappings(
this.legacyModuleMappings.legacyMappings
),
className: params['class'].substr(0, params['class'].lastIndexOf('.')),
};
}

redirect(model) {
Expand Down
15 changes: 6 additions & 9 deletions app/routes/data-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export default class DataModuleRoute extends Route {
legacyModuleMappings;

model(params) {
return this.legacyModuleMappings
.fetch()
.then((response) => response.json())
.then((mappings) => {
return {
moduleName: params.module.substr(0, params.module.lastIndexOf('.')),
mappings: this.legacyModuleMappings.buildMappings(mappings),
};
});
return {
moduleName: params.module.substr(0, params.module.lastIndexOf('.')),
mappings: this.legacyModuleMappings.buildMappings(
this.legacyModuleMappings.legacyMappings
),
};
}

redirect(model) {
Expand Down
15 changes: 6 additions & 9 deletions app/routes/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ export default class ModuleRoute extends Route {
legacyModuleMappings;

model(params) {
return this.legacyModuleMappings
.fetch()
.then((response) => response.json())
.then((mappings) => {
return {
moduleName: params.module.substr(0, params.module.lastIndexOf('.')),
mappings: this.legacyModuleMappings.buildMappings(mappings),
};
});
return {
moduleName: params.module.substr(0, params.module.lastIndexOf('.')),
mappings: this.legacyModuleMappings.buildMappings(
this.legacyModuleMappings.legacyMappings
),
};
}

redirect(model) {
Expand Down
12 changes: 4 additions & 8 deletions app/services/legacy-module-mappings.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import fetch from 'fetch';
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';

import legacyMappings from 'ember-rfc176-data/mappings.json';

const LOCALNAME_CONVERSIONS = {
Object: 'EmberObject',
Array: 'EmberArray',
Expand All @@ -10,12 +11,11 @@ const LOCALNAME_CONVERSIONS = {

export default class LegacyModuleMappingsService extends Service {
@tracked mappings;
legacyMappings = legacyMappings;

async initMappings() {
try {
let response = await this.fetch();
let mappings = await response.json();
let newMappings = this.buildMappings(mappings);
let newMappings = this.buildMappings(legacyMappings);
this.mappings = newMappings;
} catch (e) {
this.mappings = [];
Expand All @@ -32,10 +32,6 @@ export default class LegacyModuleMappingsService extends Service {
});
}

fetch() {
return fetch('/assets/mappings.json');
}

getModule(name, documentedModule) {
if (!this.mappings) {
return '';
Expand Down
10 changes: 1 addition & 9 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const envIsProduction = process.env.EMBER_ENV === 'production';
const premberUrls = require('./prember-urls');
const nodeSass = require('node-sass');
Expand Down Expand Up @@ -57,12 +55,6 @@ module.exports = function (defaults) {
},
});

let mappingsTree = new Funnel('node_modules/ember-rfc176-data/', {
srcDir: '/',
include: ['mappings.json'],
destDir: '/assets/',
});

const { Webpack } = require('@embroider/webpack');
const appTree = require('@embroider/compat').compatBuild(app, Webpack, {
staticAddonTrees: true,
Expand All @@ -72,5 +64,5 @@ module.exports = function (defaults) {
staticComponents: true,
});

return mergeTrees([require('prember').prerender(app, appTree), mappingsTree]);
return require('prember').prerender(app, appTree);
};
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"bourbon-neat": "^1.9.1",
"broccoli-asset-rev": "^3.0.0",
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^2.0.0",
"ember-a11y-testing": "^0.5.4",
"ember-anchor": "^1.0.3",
"ember-auto-import": "^2.7.2",
Expand Down
Loading

0 comments on commit cee135e

Please sign in to comment.