We have the Prop and we have the Map that we've been talking about the whole time. And just like anything else, we can give this a name. So let's just call it props.locale for convenience in our debugging. All right, so now we can see, okay, we have those three things. And now if I go and select Swedish, you can see that that is exactly the thing that invalidated it, right? And if I was to instead type in like NYC or something like that, what we can see is that now we know the filter's the thing that invalidated it.
Now this is still a pretty early debugging tool. This is just a logging just for convenience. We would expect some more elaborate debugging tools eventually built on this infrastructure. But the basic idea here is that from StarBeam's perspective, this function over here has dependencies of just three things. Now one of the things the Map is a little bit of an elaborate thing so that we can do more granular tracking. But in general, there's only three pieces of root state. It doesn't matter that we have this total function, it doesn't matter that we have this rows function, it doesn't matter that when we go and look at this rows thing, it's doing this complicated going through multiple steps, it's doing this complicated filters thing, none of that matters. At the end of the day, the only thing StarBeam actually cares about is that it has a dependency on filter, it has a dependency on the props, it has a dependency on the Map. And whenever we go and change something, let's go create a new person, right? So let's make a new person, we'll make Leia again, and we'll say pdx, right? What you can see is that the thing that invalidated is the Map, right? So at the end of the day, even though there's a lot of complexity here in your code, that complexity is all in very standard, normal JavaScript stuff. And the reactivity is really just saying that this callback here, this thing that generates JSX, has a dependency on three things. It has a dependency on a Map, on the iteration of the Map. It has a dependency on a filter. And it has a dependency on the locale, the locale prop. And now all StarBeam has to do is keep track of those three things. Whenever they change, it invalidates and notifies React and invalidates.
The nice thing about this is that if you have a lot of components in your app that use StarBeam, each individual one doesn't invalidate any of the other ones. It's like I said, it's kind of like a souped up react.memo. So what happens is without you having to say anything, simply by accessing values using normal functions, using normal getters, using normal methods, using normal access patterns, you're telling StarBeam exactly what the dependencies are. And StarBeam is able to keep track of exactly when it needs to invalidate. You can shim into the React world pretty easily, too, if you need to, and that works totally fine.
Now, one thing that's pretty cool, I think that last thing I want to say here, is if you go back and look at our table, there's no actual imports from StarBeam React or from React, right? And that's because this code, this table code, this query code, this people code, this is all pure StarBeam stuff. And that means that this exact same code will work in Svelte, it will work in Vue, it will work in Ember, and that's pretty cool. It means you can start writing libraries that are kind of like this toy example, but bigger, something like a GraphQL library, and you can write it mostly in StarBeam, in StarBeam concepts, and then expose it to React, to Svelte, to Vue using these adaptors. You don't have to build universal code with StarBeam, you can just build stuff inside of the React app, but you also could build these universal libraries, and I'm pretty excited to see what's going to happen once the ecosystem has the ability to start writing reactive code in a way that's decoupled from individual frameworks. I think that's going to be really awesome. If you're excited by this, definitely come check it out. Come to our Discord, you can come to our GitHub, you can start, you can like it, you can submit issues, you can try to integrate it, you can try to do some work. You can try to help with debugging tools, there's so much stuff going on. I'm pretty excited about how far we already got, but there's still a ton left to do. And if you're the kind of person who likes getting in on the ground floor and making a run for something, great, join us, we're excited to have you. Thanks so much, and enjoy the rest of your conference.
Comments