Skip to content
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

Merged
merged 4 commits into from
Jun 21, 2021

Conversation

cah-brian-gantzler
Copy link
Contributor

Removed the initializer to fix the implicit deprecation warning. Property options was being injected into the service. I believe to make testing easier. Moved the creation of the options property to the service init method. Fixed all the tests to allow for testing the effects of this property. Removed the user of get since its the tests (addon supports 3.16+ anyway)

The property options on the metrics service was public, but did not need to be. I left it public, but I believe it should be localized only to the init method as I believe that is its only reasonable use.

Fixes #277

@knownasilya knownasilya requested review from jherdman and Turbo87 May 7, 2021 15:18
app/initializers/metrics.js Show resolved Hide resolved
const owner = getOwner(this);
const config = owner.factoryFor('config:environment').class;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still work properly with embroider?

Copy link
Contributor Author

@cah-brian-gantzler cah-brian-gantzler May 7, 2021

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ef4 any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 _lookupAdapter. IMO, the simplest way to make it work would be to change the API so that users configure their adapters from somewhere in their own Javascript, and they import the adapters they want instead of using string names for them. Something like:

// 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 @embroider/macros setOwnConfig and use it to emit code in the addon that imports only the adapters that are needed.

Copy link
Contributor Author

@cah-brian-gantzler cah-brian-gantzler May 10, 2021

Choose a reason for hiding this comment

The 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 metrics-adapters/google-analytics.js containing

import BaseAdapter from 'ember-metrics/metrics-adapters/google-analytics';

export default class GoogleAnalytics extends BaseAdapter {
}

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?)

To only activate adapters in specific environments, you can add an array of environment names to the config, as the environments key. Valid environments are:

development
test,
production
all (default, will be activated in all environments)

Any changes to make this add embroider optimized should be in another PR. I can look into that later if you want

@cah-brian-gantzler
Copy link
Contributor Author

I think all the current concerns were addressed. Could we get the workflow run please

@cah-brian-gantzler
Copy link
Contributor Author

Could I get this re-run and considered for approval please

@jherdman
Copy link
Contributor

Build kicked.

@cah-brian-gantzler
Copy link
Contributor Author

cah-brian-gantzler commented May 29, 2021

The code I believe runs under embroider optimized, the problem is the tests themselves do not. I removed the embroiderOptimized from the ember-try, but forgot to remove it from the import so it failed linting. Sorry. (Also needed to remove from the github workflow tests.yml)

Could you please re-run workflow.

.gitignore Outdated
Comment on lines 27 to 30

# Intellij
.idea
ember-metrics.iml
Copy link
Contributor

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

Copy link
Contributor Author

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.

@jherdman
Copy link
Contributor

Build kicked. Apologies for taking so long.

@jherdman
Copy link
Contributor

@Turbo87 @ef4 any issues with this PR? I'm a little out of my depth on this one with respect to Embroider.

@cah-brian-gantzler
Copy link
Contributor Author

This PR is not meant to make this addon embroider compatible, just to remove the Deprecated Implicit Injections. I do agree that that change should not make this addon less embroider compatible and Ed already weighed in on that if you read the previous comments #279 (comment)

@cah-brian-gantzler
Copy link
Contributor Author

This PR fixes the deprecation of https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-implicit-service-injection-argument.md What are the next steps to get this PR merged?

@jherdman
Copy link
Contributor

@cah-briangantzler I'm going to merge this. Can you push up the tweak to the gitignore file?

@cah-brian-gantzler
Copy link
Contributor Author

Sure, give me a couple

@jherdman jherdman merged commit a970849 into adopted-ember-addons:master Jun 21, 2021
@jherdman
Copy link
Contributor

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecated Implicit Injections
4 participants