liveBook · Manning

View

As explained in Web Components in Action

In Model-View-Controller architecture, the presentation layer that renders an application's visual interface.

A view is the presentational layer of an application: the visual interface that users see and interact with. In a web application, it is commonly expressed through HTML and CSS. A Web Component can keep this presentation in a separate Template import while controller logic handles behavior and the model holds data. section 14.4

Separate the view from the other MVC responsibilities:

  • The view renders the interface. section 14.4
  • The controller responds to UI changes such as clicks and input changes, then updates the model. section 14.4
  • The model stores data and provides access to it, such as an exercise list or workout plan. section 14.4

A component view

An exercise-library component imports a Template, renders it into its shadow root, and displays exercise data. Its click listener delegates plan changes to the data model rather than embedding the data in the presentation. section 14.4

Listing 14.8. Exercise library component
import Template from './template.js';

export default class ExerciseLibrary extends HTMLElement {
   constructor() {
       super();
       this.attachShadow({mode: 'open'});
       this.shadowRoot.innerHTML = Template.render([

           { label: 'Jump Rope', type: 'cardio', thumb: '', time: 300, sets: 1},#1
          ... more exercises ...  ]);

   }
}
if (!customElements.get('wkout-exercise-lib')) {
   customElements.define('wkout-exercise-lib', ExerciseLibrary);
}

Inspect the component structure that renders a Template inside a shadow root. section 14.4

How Web Components in Action covers it

How deep it goes
Defines the view and demonstrates its placement in MVC, but defers detailed rendering and styling internals.
Examples
Uses an exercise-library Web Component, a separate Template import, shadow DOM rendering, and workout-plan controls.
What it assumes
Assumes familiarity with web applications and components while defining MVC roles and the view from the ground up.
What you can do after
Evaluate application structure by distinguishing presentation, event-handling logic, and stored data.
How it connects
Connects the view to Model-View-Controller, HTML, CSS, Web Components, templates, controllers, and data models.

Also explained in

Compare how 4 books explain view →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.