↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Organizing LiveView Logic with Presentation Models

The post says Phoenix LiveView is a good fit for smart interfaces, but the tutorial example is too tied to one view to be a pattern you would ship. It recommends separating presentation state from core business logic so the LiveView stays small and the transformations stay testable.

Reading notes
#

  • The author treats LiveView logic as a separate presentation layer, distinct from the app’s core business logic.
  • The example search view stores zip, stores, and loading state, and the data it receives can be further decorated for display.
  • The main benefit of extracting a functional core is simpler separation of concerns and easier testing.
  • The article proposes a Presentation Model to hold presentation state and behavior independently of the GUI controls.
  • The flow splits into preparing a query, setting loading state, running the query asynchronously, then updating results and clearing loading.
  • The Presentation Model is initialized with a one-argument search function and rejects functions with the wrong arity.
  • Tests cover creating the model, preparing a query, executing a query, and handling the empty-results case.
  • The module keeps three main operations: store the zip, set loading true, and run the search while filling stores and info.
  • The updated LiveView delegates state changes to the Presentation Model and renders from presentation_model fields.
  • The author says this makes the LiveView easier to test because the behavior is concentrated in plain, pure functions.