Build The Survey Live View

It’s time to focus on the survey LiveView. We know in broad strokes what it will look like. Users will be asked to fill out their demographic information, followed by a rating for each of our products. We’re going to approach the survey feature from the outside in, so we’ll build a route first, then we’ll mount and render the initial LiveView.

Establishing the initial state of the survey LiveView in the mount/render workflow will give us yet another opportunity to see the reducer pattern in action. We’ve seen plug pipelines iteratively transform a connection struct, and we’ve written query builders that do the same for Ecto queries. In this lesson, we’ll see that LiveView applies this same exact pattern to create and update the state of a LiveView for our users by reducing the common data structure of the socket struct. You’ll build your own LiveView reducer pipeline and use it in the mount/3 function. Along the way, we’ll get a look at one of the tools that LiveView provides to improve performance during the mount/render workflow, the assign_new/3 function.

Let’s get started with the route.

Get hands-on with 1200+ tech skills courses.