Loading video player…

Start a Walking Skeleton

In this video, you built the smallest version of Alex’s packing list that runs end to end, in a new packing-list folder inside the folder you serve with Live Preview, one file at a time.

Key Points

  • Add one file at a time, and check the page after each one. If you wrote every file first and the list stayed empty, the problem could be in any of them. Each check proves one more link, so a failure points at the file you added last.
  • The first link: the page runs its script. index.html holds a heading, an empty heading for the trip’s name, an empty list for its items, and a <script type="module"> tag for main.js. Opened with Live Preview at http://127.0.0.1:3000/packing-list/index.html, the page shows the heading, and the Console shows Packing list loaded.
  • The second link: the data reaches the script. state.js exports one trip, Beach Week, with four items. Each item already has the shape from your plan: a name, a category and a packed state, though the page shows only the names for now. When main.js imports the trip and logs its name and its number of items, the Console shows Beach Week 4.
  • The last link: the data reaches the page. render.js exports render(), which writes the trip’s name into the empty heading, empties the list, and builds one list item per item from the data. main.js imports render() and calls it once. The page shows Beach Week with Swimsuit, Sunscreen, Passport and Phone charger.
  • Change the data, and the page follows. Add a toothbrush to state.js and save. You don’t touch any other file, and the toothbrush appears at the end of the list. Saving reloaded the page, so main.js called render() again, and render() drew the list from the new data.
  • This is a walking skeleton. Each file has one job: state.js holds the data, render.js draws it and main.js starts things up. Every link between the files is in place with almost nothing on it, and the skeleton runs end to end. As a rule, build the thinnest version that runs end to end first, and check the page after each file you add.
  • It’s a toy for now. It has one trip, no categories on screen, nothing to tick off and nothing saved. Each one arrives later as a step on top of these files.

The Code

These are the four files in packing-list, as the video left them before the toothbrush:

Language: HTML Filename: packing-list/index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Packing List</title>
</head>
<body>
  <h1>Alex's Packing List</h1>
  <h2 id="trip-name"></h2>
  <ul id="items"></ul>
  <script type="module" src="main.js"></script>
</body>
</html>

state.js holds the data, one trip with four items:

Language: JavaScript Filename: packing-list/state.js
export const trip = {
  name: "Beach Week",
  items: [
    { name: "Swimsuit", category: "Clothes", packed: false },
    { name: "Sunscreen", category: "Toiletries", packed: false },
    { name: "Passport", category: "Documents", packed: false },
    { name: "Phone charger", category: "Gear", packed: false },
  ],
};

After the toothbrush step, items ends with { name: "Toothbrush", category: "Toiletries", packed: false },. Keep it, since the later steps start from these five items.

render.js draws the trip into the page:

Language: JavaScript Filename: packing-list/render.js
import { trip } from "./state.js";

const tripName = document.querySelector("#trip-name");
const itemList = document.querySelector("#items");

export function render() {
  tripName.textContent = trip.name;
  itemList.replaceChildren();
  for (const item of trip.items) {
    const row = document.createElement("li");
    row.textContent = item.name;
    itemList.append(row);
  }
}

main.js starts things up:

Language: JavaScript Filename: packing-list/main.js
import { render } from "./render.js";

render();

On the way there, main.js held one log line first, console.log("Packing list loaded");, then imported the trip to log it:

Language: JavaScript Filename: packing-list/main.js
import { trip } from "./state.js";

console.log(trip.name, trip.items.length);

Next, in Exercise: List One Trip’s Items, you’ll rebuild this list in its own starter and add a form, so Alex can add what they forgot. Then you’ll copy the code into this folder.

00:00 Your plan for Alex’s packing list is ready: a pitch, a sorted wish list, and a sketch of the page and its data. It ended on a question. What’s the smallest thing that runs end to end, from the data to the page?

00:14 In this video, you’ll build that from an empty folder. Make a new folder named packing-list inside the folder you serve with Live Preview. It’s tempting to write every feature first and open the page at the end.

00:27 But if the list then stayed empty, the problem could be in any file.

00:32 Instead, you’ll add one file at a time and check the page after each one. Every check proves one more link, from the server all the way to Alex’s items on the page.

00:43 If a check fails, look first at the file you added last.

00:48 Start with the page. In index.html, add a heading, Alex’s Packing List. Under it, add an empty heading for the trip’s name and an empty list for its items. The last line is the script tag.

01:02 Its type module lets the script import from other files.

01:07 For now, main.js holds one log line. Open index.html in packing-list with Live Preview, and show the Console under the page. The heading is on the page, and the Console shows Packing list loaded.

01:22 The server hands over the page, and the page runs its script. That’s the first link.

01:28 Next, the data. Create state.js, and export one trip, Beach Week, with four items. Each item already has the shape from your plan: a name, a category and a packed state.

01:41 The page will show only the names for now. Then change main.js so it imports the trip and logs its name and its number of items. Save, and Live Preview reloads the page.

01:55 The Console shows Beach Week and 4. The data reaches the script. That’s the second link.

02:03 Now draw the trip. Create render.js for the drawing. It imports the same trip and finds the two empty elements. Then it exports one function, render, that draws them.

02:15 It writes the trip’s name into the empty heading. It empties the list, then makes one list item for each item in the trip, with its name as the text. That’s the redraw you’ve used before.

02:27 Clear the list, then build it again from the data.

02:31 The main.js file shrinks to two lines. It imports render and calls it once. Save. Beach Week appears under the heading, with the swimsuit, the sunscreen, the passport and the phone charger.

02:45 The data reaches the page. That’s the last link.

02:50 You can confirm that the whole chain works. Say Alex remembers a toothbrush. In state.js, add a fifth item, a toothbrush, and save. You don’t touch any other file.

03:02 The toothbrush appears at the end of the list.

03:05 You changed only the data. Saving reloaded the page, so main.js called render again, and render drew the list from the new data.

03:16 What you’ve built has a name. It’s a walking skeleton. Each file has one job: data, drawing or starting up. It’s a skeleton because every link between them is in place, with almost nothing on it.

03:29 It walks because it runs, end to end. Unlike a real skeleton, it’ll grow new parts, such as a file for saving. As a rule, build the thinnest version that runs end to end first, and check the page after each file you add.

03:46 It’s a toy for now. It has one trip, no categories on screen, nothing to tick off and nothing saved. Each one arrives later as a step on top of these files.

03:58 Next, in Exercise: List One Trip’s Items, you’ll rebuild this list in its own starter and add a form, so Alex can add what they forgot. Then you’ll copy the code into this folder.

Become a Member to join the conversation.