Static properties are properties attached to the stamp itself.
const PrintMyself = stampit({
statics: {
myProperty: 'foo',
printMyself() {
console.log(this)
}
}
})
PrintMyself.myProperty === 'foo'
PrintMyself.printMyself() // call the function without creating an instance of the stamp
If you compose the stamp above with any other stamp, then it will have the printMyself method too.
const Server = stampit(PrintMyself, {
...
})
Server.printMyself()
Fun fact
Stampit's chain methods are all regular static properties: Stamp.props().methods().init().statics().conf()... etc
Using statics to compose in your own way
Often static methods are used to tweak a stamp, to compose more metadata in a domain specific way.
The example above exposes a static function which controls access to the setFactor method of your object instances.
HasFactor().setFactor === undefined // there is no .setFactor() method
const HasFactorAllowed = HasFactor.allowFactorSetter(true)
const instance = HasFactor2()
instance.setFactor(5); // we have access to the setter!
instance.getFactor() === 5 // the factor was set
Descriptor merging algorithm
The static properties are copied by assignment. In other words - by reference using Object.assign.