Currently presenters use React-style hooks such as use_local() and use_resource() to get access to reactive data sources. However, these could also work using dependency injection, similar to the way Bevy systems work:
Note that we have to invent new injectable types here (UseRes instead of Res) because the existing types don't support dependency tracking. This means that presenters cannot simply be one-shot systems (I know folks are going to ask this.)
As a first pass, we should be able to implement:
UseRes
UseResMut
UseLocal or perhaps UseState.
Unfortunately, dependency injection cannot completely replace hooks, because some hooks require runtime parameters. For example, a hook to access an ECS component needs to know which entity we're accessing the component for.
Currently presenters use React-style hooks such as
use_local()
anduse_resource()
to get access to reactive data sources. However, these could also work using dependency injection, similar to the way Bevy systems work:Note that we have to invent new injectable types here (
UseRes
instead ofRes
) because the existing types don't support dependency tracking. This means that presenters cannot simply be one-shot systems (I know folks are going to ask this.)As a first pass, we should be able to implement:
UseRes
UseResMut
UseLocal
or perhapsUseState
.Unfortunately, dependency injection cannot completely replace hooks, because some hooks require runtime parameters. For example, a hook to access an ECS component needs to know which entity we're accessing the component for.
Here's an online resource that explains how to implement dependency injection.