TL;DR
In the previous post, we explored the Elm architecture life cycle by pressing our heart like button. It is time to handle our accumulated technical debt by refactoring the Picshare application using Type Aliases. This post is part of the functional language series, and it is based on a remarkable book, Programming Elm Build Safe and Maintainable Front-End Applications by Jeremy Fairbank.
Why Refactor
By refactoring our application, we are handling accumulated technical debt of not maintainable code. We first make a feature to work. Then we refactor so we could add additional features by not breaking the current feature set.
Type Alias
You use Type Alias when you have in your codebase the same type annotation in several places. In our case, this is our record model:
{ url : String, caption : String, liked: Bool }
After the first comment, we created Model type alias; in another five, we used Model type alias:
Alias Constructor
With alias constructor, you could use type Alias to record type with values:
initialModel = Model (baseUrl ++ "1.jpg") "Surfing" False
But this is less readable because you do not have attribute names:
initialModel={ url = baseUrl ++ “27/kuce.folder/planinarska-kuca-picelj.jpg”, caption = “Picelj Park Near Zabok”, liked = False}
Remember
Refactor is an important skill in every programming language.
Comments are closed.