Fork me on GitHub
#component
<
2016-08-23
>
iwillig18:08:29

Whats the best way to have a component and make the component global?

iwillig18:08:51

right now we have our system as an argument to most of our functions but we kind of need to move away from that

hiredman18:08:04

I would say you shouldn't be passing the system to any functions

hiredman18:08:19

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

hiredman18:08:11

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?

hiredman18:08:44

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

seancorfield19:08:16

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.

seancorfield19:08:55

(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)

donaldball19:08:17

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.

donaldball19:08:09

A nice aspect of this is that the web app can function without a “complete” system; handlers without required dependencies automatically return 503 responses.