Basics
Stampit gives you several ways to create your stamps (aka factory functions).
NOTE!Any time you compose - you create a NEW stamp. Every function below always returns a NEW stamp.
const descriptor = {
methods: ...,
properties: ...,
deepProperties: ...,
propertyDescriptors: ...,
initializers: ...,
staticProperties: ...,
staticDeepProperties: ...,
staticPropertyDescriptors: ...,
composers: ...,
configuration: ...,
deepConfiguration: ...,
name: ...
}
const MyStamp = stampit(descriptor) // passing the descriptor
Or you can pass stampit-flavoured descriptor (shorter version of the standard descriptor).
const shorterDescriptor = {
methods: ...,
props: ...,
deepProps: ...,
propertyDescriptors: ...,
init: ...,
statics: ...,
deepStatics: ...,
staticPropertyDescriptors: ...,
composers: ...,
conf: ...,
deepConf: ...,
name: ...
}
const MyStamp = stampit(shorterDescriptor)
Stampit has 18 shortcut functions attached to it. For example:
const { props, methods, init } = stampit
You can create stamps from them too.
const DefaultFoo = props({ foo: null })
const PrintFoo = methods({ printFoo() { console.log(this.foo) } })
const PassFoo = init(funciton ({ foo }) { this.foo = foo })
const Foo = DefaultFoo.compose(PrintFoo, PassFoo)
The full list of the shortcut functions matches the list of keys you can pass as stamp descriptor (see above).
const { // destructuring
methods,
props, properties,
deepProps, deepProperties,
init, initializers,
propertyDescriptors,
statics, staticProperties,
deepStatics, staticDeepProperties,
staticPropertyDescriptors,
conf, configuration,
deepConf, deepConfiguration,