component

Ziad Salah 2022-08-22T09:54:44.297719Z

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!

bortexz 2022-08-23T09:42:42.106199Z

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

Ziad Salah 2022-08-23T09:47:49.172719Z

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?

bortexz 2022-08-23T10:19:40.864289Z

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
Ivan 2022-08-23T16:43:33.127889Z

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 Salah 2022-08-23T16:59:58.861429Z

Thank you both for your thoughts.