Sails.js & Vue.js - Part 4

von Manuel am 23.11.2025 um 12:00 Uhr

The fleet is assembled, the ships are enchanted, and the Chart Room is alive with data. But a true commander needs to see the entire theatre of operations at a single glance. Our components can communicate with the server, but they cannot yet speak to each other. It is time to establish a fleet-wide comms channel. It is time for the Admiral’s Spyglass.


Part 4: The Admiral’s Spyglass (Advanced State & Capstone)


Chief Architect’s Briefing (Background and Theory)

Our current architecture is powerful. Inertia passes data from a Sails controller directly to a page component as props. But what happens when a different, separate component needs that same data?

Imagine a <Navbar> component that needs to display the number of ships in the fleet, and a <FleetOverview> component that needs to list them. The data (ships) is passed to our main Dashboard.vue page. How do we get it to both the navbar and the overview without complex “prop drilling” (passing data down through layers of components)?

This is the role of a global state management library. Pinia is the current official, lightweight, and intuitive choice for Vue 3 frontendmasters.com.

Think of a Pinia “store” as the ship’s Quartermaster. Instead of every crew member having their own small inventory list, there is one central Quartermaster who holds the master list for the entire ship. Any crew member, from any part of the ship, can ask the Quartermaster for information or ask them to update the master list.

Here’s how it works with Inertia:

  1. Initial Load: Our Sails controller fetches the fleet data and passes it as a prop to our main page component (Dashboard.vue) via res.inertia().
  2. Populate the Store: The first thing Dashboard.vue does with these props is hand them off to the Pinia store (the Quartermaster) to initialize the central state.
  3. Component Access: Now, any other component in our app (Navbar.vue, FleetStatus.vue, etc.) can completely ignore props and instead directly ask the Pinia store for the data it needs.
  4. Real-Time Updates: When our Sails app receives new information (e.g., a new ship is commissioned), it can use Sails Sockets to blast a message to all connected clients. A listener in our app will hear this message and tell the Pinia store to update its state. Because the store is reactive, every single component that uses its data will update automatically and instantly.

This creates our capstone: a true real-time Single-Page Application.


Key Concepts Checklist


Mission Log: Quest - “The Fleet Command Dashboard”

We will build on our inertia-flagship project.


Mission Debrief (Review & Outcomes)

Mission Accomplished, Lord High Admiral.

You have reached the pinnacle of modern web application development. Your flagship is not just a collection of pages; it is a living, breathing application. Data flows seamlessly from the Sails database, through Inertia into a central Pinia store, and is shared across your entire Vue front-end. With Sails Sockets, that data is now updated in real-time, providing an instantaneous experience for all users.

You have mastered the entire process, from laying the first keel with sails new to commanding a real-time fleet with Pinia and Sockets. You are no longer just a captain; you are the architect and commander of a truly modern armada.

The seas of development are vast, but you now possess the charts, the tools, and the command experience to sail anywhere.


Rewards