chancancode / ember-polaris-service

Previewing Ember Polaris style services
Other
13 stars 3 forks source link

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

Open void-mAlex opened 8 months ago

void-mAlex commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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