Recent Posts

Better Redux Selectors with Ramda

Published on

TL;DR

This article turned out way longer than I’d planned. If you just want the gist of what we’ll do here, we’re going to turn these selectors:

export const getUserName = state => state.user.name

export const isLoggedIn = state => state.user.id != null

export const getTotalItemCount = state =>
    Object.values(state.items.byId)
        .reduce((total, item) => total + item.count, 0)

into this:

import R from 'ramda'

// Helper functions
const isNotNil = R.complement(R.isNil)
const pathIsNotNil = path => R.compose(isNotNil, R.path(path))
const addProp = propName => R.useWith(R.add, [R.identity, R.prop(propName)])
const sumProps = propName => R.reduce(addProp(propName), 0)
const sumCounts = sumProps('count')

// Selector functions
export const getUserName = R.path(['user', 'name'])
export const isLoggedIn = pathIsNotNil(['user', 'id'])
export const getTotalItemCount =
    R.compose(sumCounts, R.values, R.path(['items', 'byId']))

Read more

CSS Grid Is Great

Published on

Here’s a challenge for you. Let’s say you’re building a product page, and up at the top you have a container with three main pieces: one for the product name, one for an image of the product, and one for the product description. Your HTML looks something like the following:

Read more

Use JavaScript Proxies to Debug Changes to Objects

Published on

I recently found a nifty use for JavaScript proxies that helped me understand a complex application better. It’s nothing earth-shattering, and I’m certainly not the first person to have this idea, but I thought I’d share it.

Read more

Putting the “Minimum” in “Minimum Viable Product”

Published on

Hello there. Welcome to garrettnay.com.

If you’re viewing this close to the time I published it, you may be experiencing dreadful flashbacks to the early days of the World Wide Web, back before CSS, back before even table layouts were a thing. But the CSS didn’t fail to load. The CSS isn’t broken.

There is no CSS. Cue dramatic music.

Why am I doing this? First off, let me be clear that I do intend to make this site look nice eventually. Default browsers styles certainly aren’t much to look at. But since I was making this transition to a new site with a new sytem powering it anyway, I thought I’d try something a little different: build the site up gradually, all out in the open.

Read more

I Have Been Learning the Wrong Way

Published on

I recently finished an excellent course titled “Learning How to Learn: Powerful mental tools to help you master tough subjects”, available for free on Coursera. While by most measures the course wasn’t particularly demanding—the lectures were short, and the quizzes were easy enough to pass—it did make me take a hard look at how I’ve been learning.

It turns out I’ve probably been doing it wrong for most of my life.

Read more