What is the story that FP folks need to tell here, so that people don't do things like this?
What is the story that FP folks need to tell here, so that people don't do things like this?
Once that global immutable state turns out to be less than immutable (e.g you introduce the ability to change program configuration at runtime), you should look for an efficient way of do DI, which in functional programming just means "how do I pass the same first argument to a lot of functions at the same time". The Reader monad is probably the most archetypally FP approach to the problem.
Context is barely mentioned in the docs, "not recommended" by the devs. Redux is incredibly verbose and overcomplicated. Passing "global" things down in props is just madness (if everything needs it).
Personally I use context, or a singleton (which is just a hidden global really). It's naughty, but usually required for one or two things per application.
FP folks aren't sages hiding in caves who we all wait to come down from the mountains once a year with their crusty wisdom...
No one has ever approached that code and been confused or had issues tracking down bugs in my experience.
I agree it's ugly. I've found it triggers the same sense in a lot of developers that make them over-abstract code to achieve DRY at the expense of simplicity (this is just an observation, I don't have an opinion on if it's good or bad!).
A lot of my code has to be mounted in separate root components and it's not allowed to be a SPA.
In this instance, it was convenient to use event listeners, though it's very similar to calling a global.