4 ms·
We do something like this to encode our Redux states at compile-time (using TypeScript, obviously). Previously, using regular JS, the Redux devtools made track
by frio 7y ago
We do something like this to encode our Redux states at compile-time (using TypeScript, obviously). Previously, using regular JS, the Redux devtools made tracking down incorrectly implemented reducers/state transition reasonably straightforward -- but you still had to trigger a bug before you knew you had to track it down, and implement tests etc.
This kind of design pattern measurably saves us time; it reduces the volume of unit tests we need to write/update when we make changes (we still test, just... with less fear), and it prevents newer developers from making mistakes. I haven't played with Rust (beyond a couple of toy projects) yet, and articles like this remind me I'm looking forward to sinking my teeth in over the Christmas break.
- deleted 7y ago[deleted]
- amykyta 7y agoCool! Are you referring to the phantom types technique? I am interested in how you implement this in typescript. Do you have a blog post about it you can refer me to? Or even just a gist?
- frio 7y agoI'll have to read up on that. We just leverage enums and Typescript's slightly more strict type checking to state that the store can be in only certain states, and use the excellent typesafe-actions library. I'll write up a blog post. There are probably flaws in our methodology but when we took some new grads on recently, it helped a lot :).