Re:Simpler UI Logic With Finite State Machines
by IshKebab on Monday December 23, 2019 @09:38AM
(#21863817)
The fundamental problem is that Typescript (and JavaScript) doesn't have tagged unions. In Rust or even C++ using std::variant this isn't a problem.
[ Parent
| on HN ]
Re:Simpler UI Logic With Finite State Machines
by bcherny on Monday December 23, 2019 @01:07PM
(#21865582)
TypeScript does support tagged unions, actually: https://www.typescriptlang.org/docs/handbook/advanced-types....
As does Flow: https://flow.org/blog/2015/07/03/Disjoint-Unions/
Re:Simpler UI Logic With Finite State Machines
by panzerklein on Tuesday December 24, 2019 @01:18AM
(#21870266)
Every language can do tagged unions with "kind" or "tag" markers and switch statement. But it's going to be verbose without pattern matching/destructuring combo.
Re:Simpler UI Logic With Finite State Machines
by frankpf on Tuesday December 24, 2019 @11:24AM
(#21873035)
Thankfully TypeScript's type system is powerful enough (and JS's syntax flexible enough) to decently simulate pattern matching:
https://gist.github.com/frankpf/cde7f792580f731dfe886ed2d91b... (see the second file for usage)