-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
asset-map.js
46 lines (39 loc) · 1.04 KB
/
asset-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* global window, __assetMapPlaceholder__ */
import RSVP from 'rsvp';
import $ from 'jquery';
import AssetMap from '../services/asset-map';
export function initialize(app) {
let config = app.__container__.lookupFactory('config:environment');
let assetMapFile = window && window.__assetMapPlaceholder__;
if (!assetMapFile) {
app.register('service:asset-map', AssetMap);
return;
}
if (config.ifa.inline) {
AssetMap.reopen({
map: assetMapFile.assets,
prepend: assetMapFile.prepend,
enabled: true
});
app.register('service:asset-map', AssetMap);
} else {
app.deferReadiness();
const promise = new RSVP.Promise((resolve, reject) => {
$.getJSON(assetMapFile, resolve).fail(reject);
});
promise.then((map = {}) => {
AssetMap.reopen({
map: map.assets,
prepend: map.prepend,
enabled: true
});
}).then(() => {
app.register('service:asset-map', AssetMap);
app.advanceReadiness();
});
}
}
export default {
name: 'asset-map',
initialize
};