-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rwjblue/allow-opt-out-of-view-events
Allow opting out of view instrumentation hooks.
- Loading branch information
Showing
3 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
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 | ||
}; |
This file contains 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
This file contains 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