Refactor with Good Practices

You wrote a lot of code in the previous chapter. Before forging ahead with new features, let’s pause to clean up the code. In this section, you will refactor the code by using type aliases and simplifying how users like a photo.

Create Type Aliases

We have a stinky code smell in the type annotations at the moment because we reused the record model { url : String, caption : String, liked : Bool } type in multiple places. In a larger code base, that will become annoying and hard to maintain. You can fix this problem by using a type alias.

A type alias allows you to associate a type name with another type. To create an alias, you use the type and alias keywords consecutively, followed by the name of the new type and ...

Get Programming Elm now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.