This is the database. So, how do you connect to this from the front end? Well, what you can do is on the front end, you write use cloud of the to-do list. And now, I can do to-do list dot, and you can see the functions we wrote are right there. Add item with all of the strong types, all of the TypeScript, it's right there.
And you know what, I want to know what getItems does. So, I'm going to command click it, and now I'm right back on the class. Let's get me starting with a prefix. And let's see, when I go back to the front end, I can now just call dot starting with, and it'll tell me, oh, what does it want? It wants a prefix. So I put a prefix, and then it's happy. So you have full strong types throughout.
Now, what you're seeing here is that we realized even that was too hard, because you have to keep it in sync, you have to do a loading, a suspense, all of that. So we actually created something inspired by TAM stack. Instead of use query, you can write use cloud query, and this will automatically handle the loading, the sync, all of that. And it doesn't need a refetch, because if you may remember at the start, we had to invalidate.
And what invalidate does is it's server-side refetch. So, in the to-do list, you can see that we have a listed to-do items that we're getting. And whenever like to-do items data can be consumed, just as regular, like the type. And what happens is on the backend here, we can say, hey, whenever you add an item, anything that relies on this to-do list's get items, you should refetch it. So it runs it and it keeps it in sync. So that's this app, let me run it. Freestyle Dev. That's going to boot up the dev server, all that, do all the compilation. And now we're here. We have a completely persistent and live app ready to go right here. And you can see the data is not stored on the web page, it's stored persistently in the database.
So, we can actually take this further. And now, with two commands, freestyle build. That's going to build this app, prepare it for production. And then freestyle deploy. It's going to ask me what I want to name this.
Comments