Advanced Elm

Reuse Exercise

Richard Feldman

Richard Feldman

Vendr, Inc.
Advanced Elm

Check out a free preview of the full Advanced Elm course

The "Reuse Exercise" Lesson is part of the full, Advanced Elm course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to refactor their code such that the concepts of reuse are utilized effectively.


Transcript from the "Reuse Exercise" Lesson

>> Richard Feldman: That brings us to the exercises for part 5.
>> Richard Feldman: Okay, opening up the readme, so we to-dos in Page.Profile and Page.Home. If you're remembering what we just went through, there's something that those have in common, which is that they both have a feed. At the bottom of a feed is pagination, so we talked about this in the intro course.

But we have not yet talked about it at all in the advanced course. Essentially the pagination goes with the feed, and it's something that says when you click on this particular page, I want to load that part of the feed in there. So here, we have an implementation of pagination that is not being reused.

We have duplicated code on both the profile page and on the homepage. The same viewPagination function in both places, and they're both using it in the same way, but sort of implementing it in a bespoke way unnecessarily. So the goal of this refactor is to go to the profile page and the home page and to extract this viewPagination function out.

And also, you may notice that it depends on a helper function called pageLink. And move that into the PaginatedList module, which is a module built around this PaginatedList type, which has this nice little slot at the end labeled VIEW that currently has nothing under it. So the goal is to relocate that to there, and then refactor profile and home so they're both reusing that same logic from PaginatedList.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now