Function, it's not called reactivity, it's called reactive, sorry. So we pass here target, and what do we do with it? We just make a proxy out of it, just like this. And we return the proxy, and here, it's not the person, it's the target we pass. So now if we want to make an object reactive, all we have to do is reactive this.
Okay, let's try it out. Alright, let's go ahead and get the value, for example, the age. So it invokes our get hook where we lock things out, and in the real version of your reactivity, we track. So we tell the system, we want to know when the age changes, and then when it does change, we trigger it. So we tell the system, hey, this changed, and then do your thing and execute that side effect that needs to be done.
Alright, so this is proxies. Now we're going to move on to some demo where I'm going to use all of this in the back end. Alright, this is my back end, nothing impressive going on here. It's just my express server, boring, and three routes that I work with. One is join, leave, and message. They also replicate in my REST client, called Insomnia. Login, it just passes the username, message, which username and which text. And then we leave, and again the username. So there's no authentication here, there's no real interaction with real users. Those are all stuff we have to imagine that will be added later. But for the moment, let's just focus on the reactivity for this one. Alright, so the first thing we have to do, we have to add, actually, VueJS in our back end. How do we do that? We'll yarn add Vue.at.next, if you do Vue.at.next, it's version 3, alright, it's installed. Let me hide the sidebar, perfect. OK, so let's first import a few things that we need. RequireVue. And what do we need? We need the reactive function we saw earlier, we need effect, we're going to come to that later, what exactly that is, and we might use a computer property. Alright, so far so good. And let's create a reactive array that's called users. isReactive and it's an empty array to start with. Alright, so far so good, nothing happened yet because we didn't write any real code yet, but let's start by join.
Comments