A collection is just the model of your application. So in the app that I'm going to show you here as a quick demo of my framework in action, we have conferences. So I'm using an app to track the conferences that I have applied to. And I can track the talks that I've given for them, whether they've been accepted or not. And it's something that I can just use to make sure I track this. There are apps like Sessionize and some others that track these things, but not all conferences go through Sessionize. So yeah, let's take a look at it. We have the conference schema so that we can validate these things because forms are important, right? We have this conference collection that has the ID of the collection. We have the ID function that we pass to it so that we can create new conferences that have unique IDs of their own. And then we have the names that we can reference these within our application. And then finally, we attach the validator so that we can wire up things like React hook form.
The adapter is one of the most important parts because that's what makes this actually adaptable to the different providers, right? So GitHub and GitLab are adapters I've already made. But if someone wanted to make a Bitbucket adapter, all they'd have to do is follow this interface on the right. They'd have to implement the fetch repositories method, fetch file, fetch file history, create commit, create file, update file, and delete file. Just basic crud. Now, the reason that we needed this adapter is that not all of these APIs function the exact same way, and we'll dig into a way that they are slightly different in just a sec. Here, we see the GitHub adapter. In the GitHub API, they just have a single endpoint called put, and this is going to put the contents of the path in your repo. And then we use that put method inside of our create file and update file, because those are the two top-level methods that are actually used by the engine to do things. But then when we look at GitLab, we actually do something slightly different. GitLab doesn't have putting the contents of a file. They have creating a commit because, again, it's Git-based. But when they create the commit, it's either creating a file, right, with the action that we see in the middle there, or it's updating a file with a slightly different action. Those have to be in the two separate methods that we have, create file and update file, but we're going to see eventually if we were to look at Bitbucket and other platforms, that maybe they differ in some very minute way. But just wanted to show that the adapters are there to smooth over the differences between REST APIs.
Finally, there's the engine, and this does most of the actual work. This is actually calling out to the adapter for a lot of things. It's setting a lot of the state, and when you're building an application using this framework, you're probably going to be interacting with the engine most. Last but not least, we have the idea of integrations, and integrations are just what rig up to our frontend framework. So in React here, we have to create a custom hook, and this custom hook just has a use state and a use effect, and as the engine decides to notify its subscribers, it triggers the use effect, it updates the state, which then allows our components or our routes to re-trigger a render.
Comments