Fork me on GitHub
#beginners
<
2016-09-25
>
adamkowalski00:09:20

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

adamkowalski00:09:54

for example Im using posh and datascript to power my components

adamkowalski00:09:27

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

adamkowalski00:09:59

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

adamkowalski00:09:15

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

adamkowalski00:09:43

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

adamkowalski00:09:18

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

adamkowalski00:09:55

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

seancorfield01:09:16

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

adamkowalski03:09:19

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

seancorfield05:09:14

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

seancorfield05:09:05

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.

donaldball14:09:47

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