Fork me on GitHub
#component
<
2022-08-22
>
Ziad Salah09:08:44

Hi all, hope you've had a nice weekend. A few days ago I asked if it's okay to have a component in my system that does not implement lifecycle. Something that doesn't need a setup or teardown step because it has no mutable state to keep track of or manage. I received confirmation that that's fine, and the documentation confirms that it's okay too. However someone on the team had a good question: If that's the case, why even have it be a component in your system? So my question for today is: Is there any value in having a component like that in your system? The only rationale I can find is that there may be a 'glance value' benefit to having all your systems components and dependencies explicitly declared and visible to you. But I'm aware that's a bit of a nebulous thought. Would really appreciate input on this, thanks!

bortexz09:08:42

I’d say to add it as a dependency for other components with component/using

Ziad Salah09:08:49

Since it has no state, wouldn't you be able to just call a function directly from the components that 'depend' on it without having to inject it into them via the system?

bortexz10:08:40

You still need to get the component from somewhere, you can get it from global state, but imho there’s still value on the ‘dependency injection framework’ part of Component, rather than the ‘lifecycle protocol’ part

☝️ 1
Ivan16:08:33

Calling a function means that it is a very specific function that you know about. Having functionality offered by the function being pluggable (thus a component) gives you flexibility and allows the caller to not care where that functionality comes from. All the caller needs to know is that when the functionality is injected and is available under some name that can be called.

Ziad Salah16:08:58

Thank you both for your thoughts.