Digests » 262

elixir

Elixir Processes: Testing

Thinking in processes is already difficult; writing automated tests for those processes shouldn’t make it worse. Elixir provides the necessary tooling to ensure your processes are rock solid. This article explains how to use them.

OTP as the Core of Your Application

Take a deep dive into the Actor Model and learn how GenServers can be leveraged in unison with your database.

Organizing LiveView Logic with Presentation Models

LiveViews suffer from the same neck snapping, eye darting issues as GenServers. With a GenServer you define a client API, then a server API. Check the client API for the arguments passed in. Did we pattern match on the client side? Look for handle_* to see what it does, and how it handles errors. Also, testing complex logic in GenServers is less than great. But that’s fine! We have a way to deal with this by decoupling our Boundary Layer from our core business logic, breaking them into nice, pure functions we can easily test.

Error handling in Elixir: rescue vs catch

Error handling (aka exception handling) in Elixir often manifests itself with the try and rescue keywords, which correspond to errors that are triggered using raise/1 and raise/2.

Integrating Phoenix LiveView with JavaScript and AlpineJS

A common pitch for Phoenix LiveView is it allows you to create modern reactive apps without having to write JavaScript. In large part that is true. You can create dynamic server-rendered apps all in Elixir without having to write a large portion of your app in JavaScript frameworks such as React, Angular, or Vue.js. But, even so, you will still need to write a smattering of JavaScript if you want your app to have the fit and finish of a finely crafted web app. And that makes sense, as this is exactly what JavaScript was created to do.