A Clean Approach To Dynamic Component Variants
CMS sections with multiple layout variants and the if/else logic was getting ridiculous. A Higher Order Component picks the right variant based on a string - no more messy conditionals.
I build things for the web. Currently exploring the intersection of TypeScript, cloud infrastructure, and game development. This is where I share what I learn along the way.
CMS sections with multiple layout variants and the if/else logic was getting ridiculous. A Higher Order Component picks the right variant based on a string - no more messy conditionals.
AWS API Gateway doesn't have built-in basic auth. Here's how to hook up a Lambda authorizer to make it work without fighting the framework.
Swampy if-else logic for discounts getting out of hand? A simple rules engine separates rules from the data being checked - way easier to add new conditions without touching existing code.
Game enemies acting weird? Probably too many if-statements crammed together. Finite State Machines break behavior into clear states - now they actually know what they're doing.
Solving fizz buzz without a mess of if-statements. The Chain of Responsibility pattern lets you chain handlers together so new ones slot in painlessly.
Had to send different XML files to a remote server and ended up with copy-paste classes everywhere. The Strategy pattern lets you swap out the "how" without touching the "what".
Standard auto-increment IDs won't cut it when you need unique numbers per customer. Here's how to roll your own sequence generator that plays nice with Doctrine and stays atomic.
Slow aggregation queries killing your app? Use SQL views as read-only Doctrine entities - the database does the heavy lifting so your app doesn't have to.