Fork me on GitHub

If you try to keep most of your code pure, how do you deal with things that everybody might need to know about?


for example Im using posh and datascript to power my components


there is a datascript connection that needs to get passed around to every function on the off chance one of the child components also needs to make a query


or what about a theme? I want to have a swappable theme so I have simply created a map which represents it


but now I pass that around to each component so that it can use the theme stuff rather then its own


then eventually I have so many things each component needs to know about that I put them all into a map and called it an environment and pass that around


clearly something is going wrong, but I am not sure how people deal with this idiomatically


is that where people start using dependency injection or using service locators?


Take a look at Stuart Sierra's Component library @adamkowalski


thanks that looks interesting, but I feel like you still end up with a system map that you need to pass around right? Or am I misunderstanding how it works


You don't pass the whole map around everywhere. You identify system boundaries and only pass what is needed into those.


We have an application Component that has half a dozen sub-Components and those are what gets passed down the chain. But also you don't need a deep chain if you structure most of your code to be pure and keep queries and updates at the edges.


I actually perform most of the side-effecting stuff inside the components’ closures, but as sean says, I call out to pure fns to construct the transactions, as it were