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).
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 componentsetup
.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 fromgetCurrentScope()
.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 viaEffectScope.inject(key)
.