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

Updates for Ember 4 compatibility #194

Merged
merged 4 commits into from
Apr 9, 2024

Conversation

marianoggf
Copy link
Contributor

@marianoggf marianoggf commented Apr 5, 2024

This PR addresses the required changes needed for this addon to work with Ember 4

@marianoggf marianoggf self-assigned this Apr 5, 2024
@marianoggf marianoggf marked this pull request as ready for review April 8, 2024 12:15
@marianoggf marianoggf requested a review from vladucu April 8, 2024 12:15
@@ -63,6 +64,7 @@ export default Service.extend({
this._alive = {};
this._scriptLoaded = false;
this._scriptLoading = false;
this.stripeConfig = getOwner(this).lookup('config:stripe');
Copy link
Member

Choose a reason for hiding this comment

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

What's this for? I don't see it being used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vladucu Without that, the configs that come from the implementing platform (admin) do not load. Without that key data like the stripe key set on smile-admin confing/environment does not load for this addon. Also, it is used here

Copy link
Member

Choose a reason for hiding this comment

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

Without that, the configs that come from the implementing platform (admin) do not load.

Can you help me understand why?

Copy link
Contributor Author

@marianoggf marianoggf Apr 8, 2024

Choose a reason for hiding this comment

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

@vladucu The idea behind this change was inspired by this change of yours. Here is the deprecation doc I based the change on:

[...] In cases where it is not possible to convert a custom injection type into a service, the value can be accessed by looking it up directly on the container instead using the lookup method.

From what I understand now, getOwner(this).lookup is a general way of accessing registered objects within an Ember application, allowing you to retrieve not just services but any type of object registered with the application's container, which is the case for this addon

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Thanks!
If this is the case, let's please also remove this line of code that might be confusing in the future.

PS Sorry for all the extra questions. I didn't realise that this was related to implicit injection deprecation from Ember 4 because there was no change in here yo outline that. In general, it's helpful to provide answers to the WHY (ex: we need this because in Ember 4 implicit injections are no longer supported) instead of WHAT (ex: this no longer works - one can tell from reading the PR considering the change was intentional)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks @vladucu ! I already removed the redundant code (ref). Also, I will try to keep the why/what advice in mind for next time

@marianoggf marianoggf requested a review from vladucu April 8, 2024 13:11
const application = arguments[1] || arguments[0];
const { stripe = {} } = config;

application.register('config:stripe', stripe, { instantiate: false });
Copy link
Member

@vladucu vladucu Apr 8, 2024

Choose a reason for hiding this comment

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

Will this still work if we remove application.register completely?
If we want to remove completely, we should remove the initializer completely and probably just read from config/environment in the service as at the top of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I tested it and it worked!

Copy link
Member

Choose a reason for hiding this comment

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

Can I ask how did you test this pls?
I would assume that without this stripeConfig on the service will be undefined resulting in an error because the API key is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are 100% right. I was just upgrading and downgrading plans, I need to do something like updating the credit card to really call the service. Thanks for pointing this out. I have restored the file, and it's now working.

@marianoggf marianoggf requested a review from vladucu April 8, 2024 15:33
Copy link
Member

@vladucu vladucu left a comment

Choose a reason for hiding this comment

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

Left a comment here, tldr; I wonder if this actually will work as we expect it to.

@marianoggf marianoggf requested a review from vladucu April 9, 2024 12:48
Copy link
Member

@vladucu vladucu left a comment

Choose a reason for hiding this comment

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

👍

@marianoggf marianoggf merged commit 6591a45 into main Apr 9, 2024
@marianoggf marianoggf deleted the changes-for-ember-4-compatibility branch April 9, 2024 13:03
Copy link

swarmia bot commented Apr 9, 2024

✅  Linked to Task AS-407 · Upgrade to latest Ember 4.x
➡️  Part of Epic AS-405 · [smile-admin] Upgrade to latest Ember 4.x

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

Successfully merging this pull request may close these issues.

2 participants