YouTubevideo· Oct 26, 2024· 11:21· 5,000 views on YouTube
React at a moment you like. The best moments light up here.
Tools can be important and developer tools can make or break an ecosystem, depending on how good they are, how valuable they can be when you're developing within a particular tool set or a particular framework. Nuxt has an incredible dev tool selection that allows you to just get deeper into how you're building a Nuxt application.
Whether you have a react dev tools, you're familiar with the term because it's something that is just expected whenever you're building with something, whether that's Nuxt react, or even Astro has its own little dev tools specific to that framework, to that library, but. Has Livewire had anything? Not really until now. Wirespy.
This is built by Philo Hermans and it's a sleek new debug bar for Livewire. I already have a Laravel Livewire application scaffolded. I've just used Breeze. I would typically use my starter kit that I have a couple of videos about, but in full transparency, I've had a little bit of an issue. I haven't gotten to look Too deep into it, but I think there might be some weird issue within maybe Volt anonymous components within folio and wire spy.
So we're just going to use this. So first we start by installing wire spy. That's the composer require wire elements slash wire spy dash dev. Okay. We'll get all of that up and running. So the cool part about this is no matter what browser you're in, you're just going to be able to open it up. I'm going to run the composer run dev setup that is new within Laravel. We'll go ahead and open up this server.
And you see here that we have the ability, if you press command L and since I'm in arc browser, you can also have command shift L or you can do any kind of remapping within the browser itself. But command L you'll be able to see any live wire component that's on the screen. In this case, we have the welcome dot navigation. Okay. That all looks good. But you can see here that we have the initial state and then any kind of events and we can enable hot reload as well.
I changed page and now you can even see, we have the pages dot off dot register components, specific state. We also have the ability to see updates from components. So if I make some change to the state, let's go ahead and close it. If I was to say, my name and I have an email and a password, but it doesn't match when I press register, what's going to happen is we're going to, of course get a validation error, but if I was to pull up This wire spy again.
Now we see the initial state down here that we see here, but so I can actually like time travel back to that initial state before we had the issue. And you can see, we can debug of, okay, what. Was actually, registered in this state during this time. I can push it back to that state. You can see here that now we have those variables back in that time traveled States.
And again, back to initial state stuff like this is really handy when you are, when you're debugging, When you have the need for dev tools, all of this stuff comes in handy. So anyways, hot reloading, that's something that is really interesting to me, because if I want to.
Let's say my natural tendency after I change, make a change in the code would be to command R refresh it because I've been, if I'm making something and I let's say we are changing validation or something like that or maybe just a new, let's add a new input. Usually if I make the change and then fill out the form and press register, we're not going to see that.
Updated because of the way live wire components works. But now that we have hot reloading, we should see that. So I'm going to go ahead and open up the code.
I'm going to go to the register component and let's just say, for example, that we're changing the rules for the name, that this also has to have a min of, I don't know, three and yeah, actually let's go ahead and now here I'm going to turn off hot reloading. and refresh the page. Okay. We now have a men of three.
We should get some error here. Register name field must be at least three characters. Okay. But if I change this to like men of five, I save that you see I'm not going to press command R. Let's see what happens if I say, hi, test at test thing. com testing password register. You see here I pressed register. We saw the confirmation happened really quick.
This happens to me a lot, whether that's a form where anytime we're sending a Live wire directive to the server. We're requesting an action. We are submitting a form, anything that happens. Usually that's what happens. I believe if I turn on hot reloading, I'm just going to refresh the page just to be safe. I believe now that doesn't happen. So if I was to go back to the code, change this to min of three, again, I'm saving in my code, going back to the component.
And I think this is what hot reloading means. And now if I was to say hi, josh at testing. com, testing a password, okay. Register. Okay. It's not exactly what I thought it was. Maybe it's just hot reloading in the sense that if I change it to a minute of five and I was to do that same thing again, so I'm going to four. So I haven't refreshed this component, but okay. I think that did say a minimum of five characters.
Let's see if we have a history of it. Don't have a history. Okay. So that's not what hot reloading is. Maybe I can find in the wire spy repo, what hot reloading is. Plus with hot reload features, any changes to your component files automatically refresh. Okay. So it's just the change. And I think that's what we saw when I changed it from three to five. I didn't have to refresh. I do have a tendency just because of what I've learned of just pressing command R anytime I make that change.
But it's nice to know that, okay, if we're changing things like validation or if we're changing probably if we're changing a message, let's go ahead and let's pick a new component and just see what that does. So if I did like a, public string message, and we'll just set to this, public function, change message.
this message equals hello world, so we'll have a button with a wire click of change message, and then we'll echo out the message. Okay, undefined variable message. Did I not save that? Okay. There we go do have hot reloading on. So let's go ahead and see. Okay. We say change message. Hello world. Okay. I'm going to switch back. I'm not going to refresh any of that. I'm just curious.
So this message equals this has been changed. I saved that switch back. So change message. This has been changed. Okay. I think if I was to turn off hot reloading here and do the same thing, so refresh, we'll say this has been changed. If I switch this to back again, save, switch back back again. Okay.
So then I don't miss, this is probably my fault or just in the sense that I complete user error. I don't necessarily know what the hot reloading is doing in this case. Case back again. If I was to change that to hi there. Okay. That works. I don't know. But I do want to get into events because I know that's big.
So why don't we go ahead and create a new function that says send event. Dispatch, oops. And we'll just say the test wire spy dot message. Let's go ahead and send the event here just to see if we get that message in the event page. So send events, refresh. Events okay. Here we go. We have an event. So if I was to refresh the page, we don't have the event, send event. We have the event.
This is super helpful to me. Because events is one of those things where you don't necessarily know if they're there until they're there, in the sense that if I was creating an event like this, usually I would have to then create a new component to them, receive the event, or if I'm just receiving it in the same page, and then I'm debugging from there, having the event here is super nice. I do like that. I was to change this to a new message, save, send new message.
Okay. I like it. So yeah, definitely give wire spy a look, especially if you're looking to, maybe this is a, this is probably a great package. If you are in the LiveWire world and the PHP world to say, yeah, this would be something that I could contribute to. I know that would be a great option as well, but it also just is incredibly helpful for those specific elements and specific things that you need that hate that extra little bit of debugging will be incredibly useful for me in particular.
I think the two parts that I really appreciate is the events. And then the history I probably wouldn't be changing state too much in the dev tools myself just because I am very much I'm going to type all this out. I could probably automate most of it and, use tests or even cedars for that. But most of the time I'm just typing it all out myself.
But the the actual history of it, being able to say, I want to switch back to when it was blank or something like that would probably be most useful for me, not actually filling out the information because I know you can do that. So if I was going into register because I know if you're doing this, you can. Change the state right here.
And I have a small screen, so it's hard to see, but in the name, for example, I could say Josh and I could tab and I'm actually fills that out. Email Josh has Siri. com and tab. You fill it out. You see those updates shown here as well. So we can time travel back. So I think this piece itself is really interesting to me.
I don't necessarily know when I'm going to be using it a lot, but I know that when the times I actually need it, it's going to come in handy, hot reload piece. Let me know if I'm misunderstanding this completely. I don't know if I fully get what it's doing. But that could probably is mostly just me. And then events is the other piece that I think is incredibly helpful to be able to have being able to have events just show up here so that I can debug. Okay. Am I actually sending that or dispatching that event?
Like I think so yeah, tools are incredibly important for any person's workflow, regardless of the framework or library or language that you're using. I love what wire spy is doing.
I'm excited to see how this improves because debugging for live wire just got a whole lot better.