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

pattern for using a service in an addon based on an interface #19

Open
void-mAlex opened this issue Feb 8, 2024 · 2 comments
Open

pattern for using a service in an addon based on an interface #19

void-mAlex opened this issue Feb 8, 2024 · 2 comments

Comments

@void-mAlex
Copy link

use case desired here is to be able to have an addon that uses a service that would be provided by the app that uses it

one use case for this could be an intl service like ember-intl provides
it's encouraged for people to extend the service but the addon itself needs to use the service itself for the helper it provides
if the addon imports and sets the token from its own name space users will never be able to apply customizations to it and still have the addon use that version

need some way to get a hold of a token that is not known ahead of time inside the addon

@chancancode
Copy link
Owner

The add-on should publish a "well-known" token that it (and the app, and other addons) uses to inject the service: https://github.com/chancancode/ember-polaris-service/pull/15/files#diff-1bfba3f8b57376a8c7450ca36ec0a7667e35bf1906548191c108ee2a8ff65cd2R89-R106

That part is not particular tricky, however, the last we discussed this in some meeting last year it came up that we need some kind of on-demand initializer setup to 1. ensure that app customization file is pulled into the build at all, and 2. ensure that the initialization ("providing the service") reliably happened before the first time anyone uses it.

Right now you can forego the lazy benefits and just import this file from your "app.js" entrypoint, but we agreed we needed some thing better than this, perhaps requiring Embroider support

@void-mAlex
Copy link
Author

sounds to me like we should use this issue to track progress on the polaris board for 1. and 2. you mentioned as the latter seems reasonable to have a better answer than just import in app.js

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

No branches or pull requests

2 participants