In this episode, we kick things off by exploring what it actually looks like to build Alpine components without using a centralized store or state management. Basically, we try to answer the question: what happens if each component manages its own state and we need to keep them in sync?
To show why this matters, we build a simple example. There's a navigation bar that displays the total number of tasks, and a separate tasks list below it, with a button to add new tasks. The problem quickly becomes clear: we need to somehow keep these two components (the nav and the task list) in sync whenever tasks get added or removed.
We use Alpine's event dispatching to communicate between components. Whenever a task is created, we dispatch a custom event with the updated count, and then the nav listens for that event to update itself. It works, but as you'll see, it gets repetitive—every time we add or remove a task, we have to remember to dispatch an event. Initialization gets messy, too. And if we had a third component that needed the same info, we'd have to start duplicating even more logic.
By the end, it's pretty clear: manually wiring up data sharing like this is tedious and doesn't scale well. So, this episode sets the stage by demonstrating why state management is important, and leaves us ready to tackle a better approach in the next part of the course.