HaveApiKey =HaveApiKey.statics({setApiKey(key) {returnthis.conf({ apiKey: key }) // create new stamp by composing parent stamp with some configuration }})HaveApiKey =HaveApiKey.setApiKey('abcd1234')HaveApiKey.compose.configuration.apiKey ==='abcd1234'
You can access the configuration in stamp initializers (aka constructors).
constApiKeyPrinter=HaveApiKey.init(function (opts, { stamp }) {constconfiguration=stamp.compose.configurationconsole.log(configuration.apiKey) // It is perfectly safe to log secret API keys. Right?})HaveApiKey() // this will execute the initializer, and will print "abcd1234" to the console
Descriptor merging algorithm
The configuration properties are copied by assignment. In other words - by reference using Object.assign.