Whats the best way to have a component and make the component global?
right now we have our system as an argument to most of our functions but we kind of need to move away from that
I would say you shouldn't be passing the system to any functions
the component systems I have written tend to have the components as sort of top level entities, that depend on other components, and call functions passing those components the functions need as arguments
if you find yourself unable to write functions that don't take the whole system, you may have some layering / modularity issues. do you really have a system and a subsystem?
I have seen some people write programs assuming the whole system is being passed around everywhere, and maybe others have had some success with it. I view component as a tool for managing code bases and building things in a modular way, avoiding a big ball of functions calling functions all over the place. I think passing around the system runs counter to that because it breaks modularity, everything sees and has access to everything
Agree. We have a database subsystem and an environment subsystem and those operate purely in terms of a database component and an environment component respectively. Then we have an application component that has database and environment subcomponents and the application is passed in at the top-level but then only the relevant subcomponent is passed in to functions within the database subsystem or environment subsystem etc.
(we’re still migrating from a nasty global state everywhere legacy setup so our component usage is a bit piecemeal right now but slowly improving)
I have a web app using system. Each of the major route groups declares the components on which it depends, which are then threaded into the handlers along with the request.
A nice aspect of this is that the web app can function without a “complete” system; handlers without required dependencies automatically return 503 responses.