Skip to content

Instantly share code, notes, and snippets.

@tomtheisen
tomtheisen / universal-reducer.ts
Created July 1, 2020 05:57
The Last Reducer You'll Ever Need
interface UniversalAction<TState> {
type: "UNIVERSAL";
map: (previous: TState) => TState;
}
function universalAction<TState>(map: (previous: TState) => TState): UniversalAction<TState> {
return { type: "UNIVERSAL", map };
}
// all other reducers are now redundant
@tomtheisen
tomtheisen / README.md
Last active December 18, 2021 06:01
Advent of Munging 2021
@tomtheisen
tomtheisen / theory.md
Created August 17, 2022 14:08
Harmonic Music Theory Crash

This road leads directly to functional-harmony-random-progression-generator.

There's a lot more stuff in music theory.

Notes

█ █ █ │ █ █ │ █ █ █ │ █ █ │ █ █ █ 
█ █ █ │ █ █ │ █ █ █ │ █ █ │ █ █ █ 
│ │a│b│c│d│e│f│g│a│b│c│d│e│f│g│ │ 
@tomtheisen
tomtheisen / 01-1.utm
Last active December 13, 2022 17:39
AOC 2022 Mungers
#(
@/(\d+)\n(\d+)/=>{$1 $2 +}
fx /\d+/ => { _ get(max) max set(max) }
{ get(max) }
)
@tomtheisen
tomtheisen / day01.md
Last active July 21, 2023 04:47
React Journey

My Journey to the Center of the React

At the end of this, I'll know I failed if I can't write my own useState.

Tutorial

Here we go. The very first tutorial. Should be simple. https://react.dev/learn/tutorial-tic-tac-toe

It has some kind of online sandbox thing. I prefer local dev for this, as I think their sandbox is going to be hiding smoke and mirrors. I want to be able to run react on arbitrary places outside their walled gardens. Fortunately, they have instructions for doing it.

@tomtheisen
tomtheisen / README.md
Last active December 7, 2023 16:56
My Beef With React

What's wrong with React anyway?

Here's a partial list of my problems with React. Some may be matters of opinion. There may be more.

Component identity

Reconciliation matches freshly rendered components with stored state. It usually does what you wanted. Setting keys affects the algorithm somehow. I'd prefer explicit component identity to a mostly-correct heuristic.

Stale references from useState