Collected · Redux · MIT

Temporary exhibition · Hall of the Commons

What a Hundred Lines Becomes

TypeScript·2015·489 lines·17585 bytes

Curator’s note

In 2015 this was the file everyone pointed at. State management, entire, in about a hundred lines: a reducer, a current state, a list of listeners, and a dispatch that calls the reducer and then tells everyone. People reimplemented it in blog posts as a demonstration that the whole idea fitted in your head.

It is now 489 lines, and roughly half of them are comments. That is not decay, and it is worth walking through slowly, because this is what happens to a beloved small file that succeeds.

The mechanism has barely changed. dispatch is still down there around line 270, still doing what it always did. What accumulated around it is everything that a hundred-line version gets to ignore: TypeScript signatures precise enough to describe a reducer's action union, guards for the several ways people call this wrongly, isDispatching to catch a reducer that dispatches into itself, the Symbol.observable interop nobody uses but which cannot now be removed, and deprecation notices steering readers toward the newer API.

So the file records a cost that is usually invisible. The elegant version was not wrong; it was simply the version that had not yet met every way it could be misused, in every editor, in every codebase, for a decade. Documentation outweighing implementation two to one is what maturity looks like from the inside.

It hangs opposite classnames on purpose. One stayed fifty lines because it refused to answer any question it was not asked. This one answered all of them.