Code Explainers
Code explainers tagged #state-machine
javascript
const transitions = { cart: { checkout: 'shipping' }, shipping: { submitAddress: 'payment', back: 'cart' }, payment: { submitPayment: 'review', back: 'shipping' },
A finite state machine for checkout flow
state-machine
event-driven
data-driven-design
Intermediate
7 steps
typescript
type CheckoutState = "cart" | "shipping" | "payment" | "review" | "confirmed"; type CheckoutEvent = | { type: "PROCEED" }
A typed checkout state machine in TypeScript
state-machine
union-types
type-safety
Intermediate
7 steps
rust
/// A custom iterator that yields Fibonacci numbers up to a maximum value. pub struct Fibonacci { current: u64, next: u64,
Building a custom Fibonacci iterator in Rust
iterators
traits
state-machine
Intermediate
6 steps
javascript
const PENDING = 'pending'; const FULFILLED = 'fulfilled'; const REJECTED = 'rejected';
Building a Promise from scratch
promises
state-machine
microtasks
Advanced
10 steps