4 ms·
EDIT: I changed that paragraph; thanks for pointing out it no longer fit with the rest of the post. Original comment: The weakness of typing in the switch blo
by gecko 11y ago
EDIT: I changed that paragraph; thanks for pointing out it no longer fit with the rest of the post.
Original comment:
The weakness of typing in the switch blocks. I'll alter that sentence a bit; it's a leftover from an earlier version of that article where I was going to focus very narrowly on how uMsg/wParam/lParam, like the way actions are usually done in Flux apps, are decoupled to the point where it's very easy to make typing errors. Then I described why I thought they were similar to begin with, and then axed most of the original post when the entire thing switched to showing how Flux is an old pattern we've done before. I'll see if I can tweak that sentence in a way that keeps the flow going.
- DougBTX 11y agoUsing TypeScript's user defined type guards instead of a switch looks promising here, inside the 'if' the actions are type checked.
- masklinn 11y agoOr better, use Elm (or something similar) and tagged unions. That way you get type-checking and exhaustive-checking of your message types. You still have a big match (~switch/case) but now the compiler yells at you if you've forgotten to handle a message tag or if you're not unpacking the right types from it.