paulgray.net

The Gray Side of Software

I'm a software engineer, and sometimes I write some stuff.

A Proposal for an Alternative Design for Hooks
An Alternative API for hooks based on functional programming patterns.
October 31, 2018
preface: If you haven’t, please read the Hooks Intro, otherwise this post won’t make sense to you. To the React team: Thanks for a great framework. I enjoy using React every day, and it’s all credit to your hard work. Hook functions (currently as of 10/31/2018): Have signatures which are indistinguishable from normal functions. Have hidden complexity around ordering hooks. Have no way to be unit...
Chainable Components
A composable API for reusable React components
September 04, 2018
The easiest way to write DRY reusable React components is with Render Props. However, they aren’t inherently succinct or easy combine. HOCs are an equivalent way to write DRY React components, and offer more composability, but leave a lot to be desired. Fortunately, we can realize a more composable and succinct API for reusable React components. The Essence of reusable React...
Typing HoCs
Writing type signatures for Higher Order Components
July 13, 2018
The process of writing a type signature for a HoC can be daunting at first. In this post, I’ll build an HoC and detail the process of writing a type signature for it. The HoC we’ll develop will be simple; it’ll take a promise, and handle the state-management, providing the inner component with the value, and whether it is loading...
How to write an HOC (in 3 easy steps).
Writing HOCs is complicated, follow these three steps to make it easier.
January 02, 2018
How to write an HOC (in 3 easy steps). A lot of times when writing software we end up solving similar problems in similar ways. Sometimes we even copy-paste a chunk of code and change just a little bit of it. If you’ve done this before, don’t feel bad; every developer has done this at some point in their career. If...
Testing for Race Conditions with Redux
This post will explain how to write unit tests for race conditions in a redux reducer.
November 29, 2017
One type of error that causes bugs is race conditions. They are often hard to detect and reproduce since they only happen in special circumstances. If you’re using redux to store your state, it’s easy to write unit tests that account for these special circumstances. Let’s look at an example. The search results screen Suppose we have a long list of items which...
Why you need keys for collections in React.
This post will explain the importance of keys in React and some edge cases to consider when choosing them.
July 25, 2017
Keys are important when rendering collections of items in React. They are used under the hood by React to determine what needs to be rendered or re-rendered. React does not render duplicate keys. Let’s consider this array of numbers: const nums = [1, 2, 3, 5, 2]; (Notice the duplicate value, ‘2’) Now...
Types as a convenience, Assumptions.
Minimize your assumptions with types.
December 16, 2016
Minimize your assumptions with types. As developers, we make assumptions every day when we write code. I assume that a method in that library that I’m using didn’t change when I bumped the dependency’s patch version. I assume that the data I get back from /api/users is an object, not an array. I assumed that my wife wanted an honest opinion when she asked...
Types as a convenience, Inference.
Type-safe doesn’t mean verbose.
December 16, 2016
Type-safe doesn’t mean verbose. A common criticism of typed languages is that they are unnecessarily verbose. While that idea may have some merit with languages like Java, features in newer typed languages have come a long way. The Typescript compiler uses a method known as type inference to make type-safe code less cluttered. Type inference occurs when the compiler can determine a...
Types as a convenience, Intro.
Bringing types to your UI.
November 04, 2016
Bringing types to your UI. As a developer with experience in both type safe and weakly typed languages, I much prefer the former, simply because I enjoy it more. In a series of following blog posts, I’ll attempt to make an argument for types, and make some recommendations of where I think they bring the most benefit. If you’re already sold on...
What’s the point of CASA?
Indexing learning media.
June 24, 2015
Currently, there’s no standard way of sharing and consuming learning content. Most LMS’s have a way to add a generic “Content Item” link to a course. If it’s more than just static content, there’s probably been some expensive custom integration developed in order for integration to occur. If you’re lucky enough to have a tool that supports LTI, your organization...