Skip to content

Instantly share code, notes, and snippets.

@RuslanZavacky
Created September 19, 2016 16:26
Show Gist options
  • Select an option

  • Save RuslanZavacky/524bb9a1b2e52cf8687a3f3aa344e093 to your computer and use it in GitHub Desktop.

Select an option

Save RuslanZavacky/524bb9a1b2e52cf8687a3f3aa344e093 to your computer and use it in GitHub Desktop.
Asset Map initializer and service
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
};
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