-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed initializer. Create options in server init #279
Changes from 3 commits
6862e16
2cd1d29
4e20dd9
52d6032
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,14 @@ export default class Metrics extends Service { | |
*/ | ||
enabled = true; | ||
|
||
/** | ||
* Information about the active adapters from environment.js | ||
* | ||
* I think this could have been isolated to the init method only, but since | ||
* was public before, would have been a breaking change | ||
*/ | ||
options; | ||
|
||
/** | ||
* When the Service is created, activate adapters that were specified in the | ||
* configuration. This config is injected into the Service as | ||
|
@@ -49,8 +57,13 @@ export default class Metrics extends Service { | |
* @return {Void} | ||
*/ | ||
init() { | ||
const adapters = this.options.metricsAdapters || emberArray(); | ||
const owner = getOwner(this); | ||
const config = owner.factoryFor('config:environment').class; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this still work properly with embroider? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know. Not sure how to test. The original import of ../config/environment did not seem to work correctly when running in tests if I tried to use that in the service There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this does work in embroider, safe, the addon doesnt work under optimized for various reasons, not sure if this is one of them or not. I created another PR to add embroider try scenarios #280 although I dont understand why some of the checks were cancelled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ef4 any thoughts on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is fine. The part of this addon that isn't going to work with optimizations is // app.js
import { configureMetricsAdapter } from 'ember-metrics';
import GoogleAnalyticsAdapter from 'ember-metrics/metrics-adapters/google-analytics';
configureMetricsAdapter(GoogleAnalyticsAdapter, { optionsGoHere }); Alternatively, you could probably keep the adapter config as it is, but send it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of this PR was to fix the deprecation of no implicit injection. Not to make it embroider compatible. I think the question was if the one change I made was compatible and Ed confirmed it is. For a PR to make it embroider compatible Ed is absolutely correct that the lookup adapter would fail unless the consuming app did something. I would suggest that the app create a a metrics adapter (as Ed stated above) in the following file
The app only creates the ones it uses, it gives a clear place where they can override options if needed and requires no code change to this addon. Just an update to the docs that you dont have to create empty exports like this in ember classic or embroider safe, but you do if you want your app to be embroider optimized There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed the point that really the factoryFor line would be for ember classic compatibility, once you go embroider optimized you would not configure the adapters in the environment.js at all but instead but the above method. The ability of being able to specify if they are enabled in production or dev would have to be done a different way, but it would be a small change that you are bascially opting into by going embroider optimized. From docs (How often is this really used?)
Any changes to make this add embroider optimized should be in another PR. I can look into that later if you want |
||
const {metricsAdapters = []} = config; | ||
const {environment = 'development'} = config; | ||
this.options = {metricsAdapters, environment} | ||
|
||
const adapters = this.options.metricsAdapters || emberArray(); | ||
owner.registerOptionsForType('ember-metrics@metrics-adapter', { instantiate: false }); | ||
owner.registerOptionsForType('metrics-adapter', { instantiate: false }); | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO this belongs in your global git ignore. https://stackoverflow.com/a/7335487
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, created. Dont want to update the .gitignore and cause the build to need to be kicked off again. Can fix this up if I have to update anything or just before the PR is accepted.