Write Rust events with ease

Picturesque photo of a mountain range
Picturesque photo of a mountain range
Photo by J Scott Rakozy on Unsplash

I recently wrote an article about writing events in Rust. I must admit I wasn’t entirely satisfied with the solution I came to. My previous code used a clunky macro-capture pattern to define a signal and produced receivers that couldn’t easily transform the data like event receivers should be expected to do.

Thus, we’d have to write custom transformations for each of our receivers — not very ergonomic. I decided I could do better! What I came up with is ultimately declared like this:

Building and Collapsing Expression Trees

Photo by Alex Perri on Unsplash

Since Rust has become so wildly popular and has amassed such a dedicated following, I decided to put down my beloved JS and learn Rust recently. And I must say, it’s not a journey for the faint of heart. Luckily (although misleading in some rare occasions) the compiler is your best friend — it will nearly always tell you what you did wrong, and will even offer helpful solutions. After you spend some time with it and get over the steep initial learning curve, you’ll begin to love Rust — I do!

Today I’d like to implement my favorite data…

Photo by Weston MacKinnon on Unsplash

I’ve been playing around with Rust a lot lately. I was really inspired by a guy named Tom Leys, who used the Godot game engine’s NativeScript feature combined with the Godot C bindings for Rust to make a crazy space factory game. Seems to be in development still but looks pretty amazing. You can read about his adventure here. But Rust is gaining ground everywhere lately, it would seem. Rust is a very capable language and you have a lot of options (every option?) when it comes to build targets.

Anyway, I love the luxury of having access to functions…

Handling Impure Actions in a Pure Application

Photo by Héctor J. Rivas on Unsplash

If you’ve been studying up on Functional Programming in JS, you’ve probably heard about pure and impure functions, and side-effects. If not, I’ll quickly recap — a pure function is one that when given the same parameter any number of times, for each of those invocations it will produce the same result. Pure functions should also have a tangible result. Impure functions on the other hand may produce a different result when given the same parameters. Something non-static is happening behind the scenes in these impure functions. Those non-static factors are called side-effects. Functional programmers always say, ‘avoid impure functions…

Monad Explained Simply

Photo by Michael Dziedzic on Unsplash

Monads are all-the-rage these days in the JS world. I’d be surprised if any serious JS developer hadn’t heard of Monads. But just in case you haven’t, I like to describe a monad as a fancy box. It’s a special box. You can’t (well, you shouldn’t be able to) see exactly what’s inside the box, but you can know that this box holds values of a certain type, and exposes three primary operators with which we can modify or take out the content of that box. Those operations are what I call the Monad Interface.

OK, so Monad isn’t exactly…

How I Went From House Painter to Web Developer

Photo by Dane Deaner on Unsplash

How It Started

I didn’t finish college. I was married by the time I was 21. And we had already had our first baby by then— he was my best man at the wedding. I had and have no regrets about this, it was what we both wanted to do. But it did put our family in a financial pickle. For the next couple of years I worked maintenance jobs and trades jobs, and finally settled on painting — it was super consistent with the company I found and not terribly dangerous or taxing physically. …

Part 2: Using Middleware More Effectively

Photo by Grant Durr on Unsplash

A Comment and a Complication

My last iteration of this two-part attracted the attention of Mark Erikson, one of the gurus behind the Redux Toolkit (aka RTK), and a general Redux pro. His reddit comment combined with another scenario made me decide that my implementation regarding middleware was not robust enough.

Firstly, Mark and I had a short community discussion on Twitter about the differences between the real middleware used by RTK versus my naïve middleware. He pointed out his reddit comment and explained that the real middleware were pre-processors that built up a pipeline of logic, whereas my implementation used post-processing and no prescribed…

Redux/Flux: The Bigger Picture

Photo by Grant Durr on Unsplash

I’ve been on a minimal-extremism kick lately. My goal has been:

  • Not to use outside libraries.
  • Not to use transpilation middleware (so native ES6, no babel, all import paths are relative paths, drop support for old browsers)
  • Keep it as vanilla as possible. With modern browsers you can write modern JavaScript with no downside, so the new ‘vanilla’ is ES6+ syntax.

This process has led me to some fun projects, including Olive, a SPA framework in just over 300 lines of code, most of which is a single file. Part of that codebase is an implementation of Redux that I’m…

Rethinking How We Use VanillaJS and Native DOM

Photo by Jéan Béller on Unsplash

My Relationship With the DOM

I just love playing with JavaScript code that generates or manipulates the DOM. If you’re reading this and wondering, ‘what is the DOM?’, fear not. It is simply a tree of JavaScript objects that represents an HTML document.

I personally have a weird secret obsession with creating alternative ways to make reactive application drivers using the DOM (you know, like React, Vue, Angular, Svelte, etc.). I have written about it a few times, in fact. There are bunches of approaches to creating a DOM from code:

  • The Virtual DOM — pioneered by React, virtual DOMs are fast because all the…

Implementing Monads in Rust

Photo by Zane Lee on Unsplash

I’ve done a lot of writing about functional programming. But mostly in JavaScript. I love the simplicity of declarations that are possible thanks to JavaScript’s dynamic typing system. It makes defining generic things very easy — a concept that is much more complicated in strongly typed languages. One generic concept that I love expressing in JS is the functional keystone known as the Monad. A Monad is an encapsulation of an associative binary operation. In other words, you can call map on it with an appropriate function parameter to change the inner value — even its type. It wraps some…


Programming maniac, #JavaScript zealot. I'm crazy about #FunctionalProgramming and I love Rust. ETH coffee fund: 0x0c37584674e7143e03328254232102973a9cd468

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store