This is a conversation on the DI pattern in ReactJS.
This article from the folks at 8th Light is great. The author explains how it makes component very easy to test. It encourages unit testing rather than integration testing.
In essence:
It also allows for substitution of a dependency with a mock, or fake, during testing.
I know the importance of loose coupling of dependencies and how it helps in building software that is resilient to change.
I came across this tweet and it made me start thinking about the DI pattern we used in Shiga.
This is an intersting line:
It makes a codebase really difficult to ramp up on because you can't trace things bottom-up, only ever top-down.
I ran into this issue a lot in Shiga where it felt complicated. For me to understand a child's dependency, I had to go to the Parent. If the Child is deeply nested, it creates this sorta Dependency drilling situation where you have to find the parent and the parent's parent.
The top-down approach is complexity. Complexity in the sense that it is:
- Hard to reason about
- Components are pretty much static. We didn't really extend them after creation.
I wonder if the complexity could be improved