 So this time, I want to talk about the message bus. It's something that I built, but you might be asking yourself, why do we need a message bus? Or, Surma, what actually is a message bus? That's what I wanted to figure out today. So a message bus is something that I have seen game developers use to write more decoupled code. And I looked at it, and I thought, this could work really well on the web. And so I gave it a try, and it turned out to be quite effective. So let's talk about how a message bus actually works. So the message bus is basically an entity in your system. I implemented it using a class, but it could also just be a standalone function. And it offers two methods. One of them is subscribe, and the other message is called dispatch. If you call subscribe, you can say that you're interested in messages of a certain type. With dispatch, you can publish a message on something that is called a topic or a channel. And if you do that, all subscribers on the same channel are going to get a copy of that message. So if you look at this, you might think that this sounds somewhat familiar, because it is a very similar concept to events. So why did I reinvent the wheel instead of reusing events? And the answer here is that events are mostly tied to DOM elements, which is something with a visual representation. This, however, is a purely architectural element, and it didn't really make sense to me to tie that to a visual element. I wanted this to also work in a Node.js environment if I needed to. And in Node.js, we don't really have a DOM, so I wanted to write it from scratch instead so that it can work in both Node.js and on the web. So when do we use our message bus? I want to talk about two examples, and the first one is the router that we built in the last episode of Commit Lock. If you remember, the router intercepts clicks onto links and turns them into these really nice transitions from the main page to a blog post and vice versa. And now, like with every blog post, we have some analytics module installed so that we can see if our user actually interested in the content, how long they spent greeting it, but also since we now have a router and basically have a single-page application, analytics doesn't actually know when the user went from one blog post to the next one because there is no actual navigation happening. So one thing we could do is to load the analytics module as a dependency of our router, and whenever a navigation happens, we could tell analytics about that. But it would be much better and much preferable if these two modules didn't know anything about each other. And this is exactly where the message bus comes into play. If we look at the code of our navigate function in the router, you can see that at the very last step, we publish a navigate message onto the message bus. And that means that every module in our entire app can subscribe to the navigate event if they're interested once the user switches to a new blog post. So if we now look at the analytics module, you can see it's the normal Google analytics snippet thing, but the last couple of lines we subscribe to our message bus to the navigate channel. And whenever a message comes in, we tell Google analytics that the URL has changed and that the view counter should be increased by one. And that means we're now tracking views correctly even if it is a single-page application without these two modules knowing anything about each other. So the advantage here is that now the router and analytics can load completely independently. The router can come first, and whenever any of the other modules load, they will just start working together as soon as they can without you having to do any kind of linking them up. Now, I promised you a second use case, but that second use case actually involves service worker. So I'm gonna wait with that until the next episode where we are finally gonna talk about how we make this blog work offline. So if you're interested in that, you should click the subscribe button so we get a notification when the next video comes out and I will expect to see you here.