Created
September 19, 2016 16:26
-
-
Save RuslanZavacky/524bb9a1b2e52cf8687a3f3aa344e093 to your computer and use it in GitHub Desktop.
Asset Map initializer and service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import RSVP from 'rsvp'; | |
| import $ from 'jquery'; | |
| import AssetMap from '../services/asset-map'; | |
| import Configuration from 'app/config/environment'; | |
| export function initialize(app) { | |
| app.deferReadiness(); | |
| // isProductionLike is a property that decides which environment | |
| // to treat as production. Eg. staging is production like | |
| if (!Configuration.isProductionLike) { | |
| app.register('service:asset-map', AssetMap); | |
| app.advanceReadiness(); | |
| return; | |
| } | |
| const promise = new RSVP.Promise((resolve, reject) => { | |
| $.getJSON('/assetMap.json', 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: initialize | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Service.extend({ | |
| enabled: false, | |
| map: {}, | |
| prepend: '/', | |
| resolve(name) { | |
| let map = this.get('map'); | |
| return this.get('prepend') + (this.get('enabled') ? map[name] : name); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment