Hacker News new | ask | show | jobs
by heycosmo 1950 days ago
I have a simple rule for GUI design: build trees not graphs. Write components that accept a state snapshot and broadcast changes. If component A listens for state changes from B, then A is a parent node of B. If A sends state to B, then A is a parent of B. Components reconcile state before broadcasting changes toward the root of the tree.

Often there is a price paid in brevity, but I believe it is worth it. It may seem annoying to propagate a click explicitly through 5 parent components just to sum clicks into a count widget, but as soon as a short circuit is made, you've created a graph, and you lose the ability to isolate GUI sub-trees for testing/debugging.

1 comments

This makes visual redesigns take foreeeeever though. Imagine moving a component from the main area of your app into a menu dropdown in the navbar, now you have to tear out all those props that you painstakingly passed down through 10 intermediary layers.