Well, it sounds quite a lot for just one key press. And here signals may be useful. So, in this case, what might be a signal? The signal might be actually text. It's like a value, static values, that we can work with at any time, as well as the fact that it changes over time. And maybe a bit of what it is about.
It's a classical diagram. Nothing special here. On the left side, we have just a value. Okay, we can, what is the value, we can access it at any time synchronously. On the opposite side, we have a sort of observable, just a stream of events, like without the sort of static value, but rather you need to listen for it. And the signal is something in between, first of all. Usually, here it's like a bucket. There's a value that you can access at any time, as well as you can subscribe to it, so it behaves in both ways.
Well, this is another presentation. So, signals in general, it's a concept of reactivity. I'm not going to dig into reactivity, but, yeah, in general, we need to react on some change in state and update in a reactive way our UI, or maybe execute some business logic. Well, here is just an observable part of our signal, like we're applying to the stream of events, we're applying the bonds function in this case, and getting another stream. Well, what about the usage? There are quite a lot of libraries, frameworks that contain this concept of signals. For sure, there are signals in Angular, as well as Angular uses ArigGS.
Probably, the term signal become popular after solid.js introduced it. And for sure, there is a standalone library, ArigGS. It's not only about the signals, but there is a concept called behavior subjects that may contain the value that can be accessed synchronously. There is a standard proposal, for sure. At Grammarly, we have our very own library that was developed quite a long time ago. It provides a code called GrammarlyFocal, and it also basically provides or shares the same concept of signals, and there are a lot more examples.
Well, enough with sort of introduction. Let's look at how we are leveraging the idea of signals in our Grammarly editor. It's like the same screen, nothing fancy. I'm not going to dig into details, but let's look at how it might be, in theory, implemented with React. This is very simple, just for the sake of the demo.
Comments