TL;DR
In the previous post, we explored refactoring the Picshare application using Type Aliases. Let’s keep refactoring by moving business logic from the Elm view function. 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.
Where To Put Business Logic
In our previous post, on Gist line 42, we have Elm refactor smell. Our ViewDetailedPhoto function has if statement around a Msg type union. Message value is business logic and should always be set in update Elm function. Line 38 has also if logic, but around HTML element, and it is ok to have view logic in the view function. Follow steps in Gist to refactor our Picshare application.
Check with the compiler for a syntax error. If there was no any, run application and verify that you like the heart is still working, despite the refactoring.
Remember
Elm business logic belongs to the update function.
Comments are closed.