Skip to content

Commit

Permalink
Refactor to avoid app/instance-initializers/ for Ember 1.11 support.
Browse files Browse the repository at this point in the history
Due to an issue with ember-load-initializers we cannot have a file in
`app/instance-initializers/` when running against Ember < 1.12.

That is fixed upstream in ember-load-initializers#0.1.7, but is not
commonly in use yet.

---

For now, move this to the `addon/` dir and register it manually during
the main initializer.
  • Loading branch information
rwjblue committed Sep 9, 2015
1 parent 3cf938c commit d846937
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
37 changes: 37 additions & 0 deletions addon/instance-initializers/ember-perf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Ember from 'ember';

// this lives in addon/ because when running on Ember < 1.12
// the ember-load-initializers project will attempt to call
// `Ember.Application#instanceInitializer` which does not exist.
//
// This was fixed upstream in https://github.com/ember-cli/ember-load-initializers/pull/21,
// but is not in widespread use yet.
export function initialize(instance) {
// in 2.1 the ApplicationInstance instance has a public `lookup` method
const container = instance.lookup ? instance : instance.container;

// in 2.1 the ApplicationInstance uses `_lookupFactory` to avoid making lookupFactory public
// along with `lookup`
const config = container._lookupFactory ? container._lookupFactory('config:environment') : container.lookupFactory('service:ember-perf');
const emberPerfConfig = config.emberPerfConfig || {};

let shouldSubscribeToViewEvents = 'logViewEvents' in emberPerfConfig ? emberPerfConfig.logViewEvents : true;

if (shouldSubscribeToViewEvents) {
const emberPerf = container.lookup('service:ember-perf');

Ember.subscribe('render', {
before(name, timestamp, payload) {
emberPerf.renderBefore(name, timestamp, payload);
},
after(name, timestamp, payload) {
emberPerf.renderAfter(name, timestamp, payload);
}
});
}
}

export default {
name: 'ember-perf-instance-setup',
initialize
};
7 changes: 6 additions & 1 deletion app/initializers/ember-perf.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import Ember from 'ember';
import EmberPerfService from 'ember-perf/services/ember-perf';
import RouterExt from 'ember-perf/ext/router';
import RouteExt from 'ember-perf/ext/route';
import config from '../config/environment';
import instanceInitializer from '../instance-initializers/ember-perf';
import instanceInitializer from 'ember-perf/instance-initializers/ember-perf';

const {
Router, Route
} = Ember;

if (Ember.Application.instanceInitializer) {
Ember.Application.instanceInitializer(instanceInitializer);
}

function injectServiceOntoFactories(emberPerf, application) {
const {
injectionFactories
Expand Down
27 changes: 0 additions & 27 deletions app/instance-initializers/ember-perf.js

This file was deleted.

0 comments on commit d846937

Please sign in to comment.