What is a Stamp
Last updated
Last updated
Stamp is a composable factory function.
NOTE
Factory functions create and return new objects.
Go to to learn how to create a Stamp.
But unlike plain functions, Stamps carry around the metadata about the object they are going to produce. The metadata is attached to the Stamp.compose
object. Another name for that metadata is "stamp descriptor" or just "descriptor".
There are 11 types of metadata:
You, the developer, is allowed and encouraged to operate that metadata manually if needed.
For example, you can always check which methods an object instance will have:
To understand if your object is a stamp you need to check its property .compose
like this:
The main reason why stamps exist is the ability to freely compose stamps together.
The line above is identical to these:
NOTE
Every time you call
stampit
or.compose
you create a NEW stamp.
There is no naming conflict resolution in stamps by default. This means that in case of conflicting properties/methods the last composed overwrites all previous.
This behaviour is by design.
NOTE
To create a new stamp from scratch you would need to use one of the JavaScript modules available:
You can use both stampit
s same way as if it was the compose
function. But you cannot use compose
function same way as stampit
. For example, these lines generate same stamp:
However, stampit
adds few more handy APIs to your stamp (see comments):
Whereas compose
does not have the handy API (see comments):
NOTE
The stampit
and .compose
functions are doing only one thing: merge stamp descriptors according to the .
If you really need to make sure none overwrites your method you can use stamp. Compose it into your stamp. However, in our practice stamps tend to stay quite small, so that conflict resolution is never needed.
- the
- the same as the compose function above, but provides some additional nicer API
- the same as the @stamp/it
above, but optimized for browsers
The stampit nicer API is nothing else but few additional in your stamps. That's it.