So we had a look at a lot of decorators how you work with them how you can configure them how you can
do stuff with them what you can do with them and this hopefully shows you the complexity but also the
power of decorators and how you can think about them how you can use them.
Now you're not only able to create your own decorators there also is a rich ecosystem out there of packages
and frameworks that rely on decorators for example CLOs and validator.
If you search for T S Class validator you find a package which basically has a more elaborate implementation
of our own custom validation logic.
We worked on this package can be added to any project you're working on and then you can simply import
a bunch of decorators or decorator factories as you can see since we execute them here at home to your
properties with or without some extra configuration depending on the validator it is.
And behind the scenes this will manage such a registry you could say such a configuration object in
the end store your validator is set up for the different properties in your different classes and then
give you validate method which you also import from the package which you can execute and pass your
object to to apply all the validation logic you set up in the class.
So it's basically doing what we just did just with more validators and with all the heavy lifting done
for you.
But of course it helps to understand how it is generally works since we built it on our own here in
a more nave version.
Now besides this package of course we also have angular for example angular is a framework which I mentioned
early already which heavily relies on decorators like this component decorator which allows you to create
some wear which allows you to assign some dynamic HDL code which taps into properties of your classes
as well with a special syntax added by angular to then render some dynamic content onto the screen.
So here angular does more than just offer these decorators but the decorators are a core part of angular
and last but not least I also want to show you nest J.S. nest J as is a service side javascript framework
for note J.S. which also heavily utilizes TypeScript and this also embraces decorators.
Are you use decorators to define controllers and routs the methods which users have to use on their
age the p requests to trigger certain functions and also a lot of other decorators you can use to extract
data from incoming requests and so on.
So here this framework also again offers all these decorators for you so that you can just add them
to your properties to your methods to your classes and add extra functionality which the framework then
in turn also takes into account when it executes your code.
So here again decorators are used for meta programming to add extra configuration extra logic which
then is taken into account by in this case the code of the framework which executes your code or which
works together with your code and that's it.
For decorators this hopefully gives you a good overview of what you can do with decorators why they
can be very helpful and how they generally work.