What is a Stamp
Stamp is a composable factory function.
NOTE
Factory functions create and return new objects.
Go to API Quick start to learn how to create a Stamp.
Stamp's metadata (descriptor)
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 standardized 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:
Ducktyping a stamp
To understand if your object is a stamp you need to check its property .compose
like this:
Composing stamps
The main reason why stamps exist is the ability to freely compose stamps together.
The line above is identical to these:
The stampit
and .compose
functions are doing only one thing: merge stamp descriptors according to the stamp specification.
NOTE
Every time you call
stampit
or.compose
you create a NEW stamp.
Naming conflict resolution
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
If you really need to make sure none overwrites your method you can use @stamp/collision stamp. Compose it into your stamp. However, in our practice stamps tend to stay quite small, so that conflict resolution is never needed.
Creating stamps
To create a new stamp from scratch you would need to use one of the JavaScript modules available:
@stamp/it
- the same as the compose function above, but provides some additional nicer APIstampit
- the same as the@stamp/it
above, but optimized for browsers
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 nicer API is nothing else but few additional static methods in your stamps. That's it.
Last updated