vuejs / rfcs

RFCs for substantial changes / feature additions to Vue core
4.85k stars 549 forks source link

Provide/inject for EffectScope #562

Closed rockwalrus closed 9 months ago

rockwalrus commented 1 year ago

What problem does this feature solve?

When writing composables that are used by both a component and its descendants, it would be good to inject the dependencies, but this is not possible because components cannot provide to their own composables. EffectScope.provide can also be used to inject dependencies into composables in contexts other than component setup.

What does the proposed API look like?

EffectScope.provide(key, value) would provide a value to the scope and all nested scopes that do not override it. In the common case, users will call it on the result from getCurrentScope().

While it could be desirable to have inject inject from the current scope, this probably would lead to backwards compatibility edge cases. Instead, they are injected via EffectScope.inject(key).