make-compose
Hackable implementation of the 'compose' specification
Install
$ npm i make-compose
API
The following is written using rtype type notation.
interface Any; compose: Compose; Descriptor instance: Void|Any ingerface Descriptor methods?: Object properties?: Object deepProperties?: Object propertyDescriptors?: Object staticProperties?: Object staticDeepProperties?: Object staticPropertyDescriptors?: Object configuration?: Object deepConfiguration?: Object initializers?: Initializer interface Composable: Stamp|Descriptor interface Stamp
MakeCompose(options: Object) => compose: Function
This function creates and returns the compose
implementation. The options
argument can have the following key-value pairs:
-
mergeComposable: (dstDescriptor: Descriptor, srcComposable: Composable) => dstDescriptor: Descriptor
- merges (mutates) the second argument into the first argument. Returns the first argument. Supply it to track composition. -
createStamp: (descriptor: Descriptor, composeFunction: Compose) => Stamp
- creates new stamp from the given descriptor and thecompose
function. Supply it to track each instantiated stamp. -
createFactory: (descriptor: Descriptor) => Function
- creates a factory function from the given descriptor. Supply it to override factory function creation. -
createObject: (proto: Object) => Object|Any
- given the prototype object creates a new empty object form it. Default value isObject.create
. Supply it to tweak the objects the stamp are gonna return. -
assign: (dst: Object, src: Object) => dst: Object
- supply it to override the defaultObject.assign
implementation. -
merge: (dst: Object, src: Object) => dst: Object
- the stamp-specific merge function. Supply it to override the default implementation.
mergeComposable
Use it when you need to track or override each time a composable is merged to the new descriptor object.
;const compose = ;
createStamp
Use it when you need to track or override each new stamp created.
;let counter = 0;const compose = ;
createFactory
Use it when your factory function needs to be different to the default one.
;let counter = 0;const compose = ;
createObject
Use it when you need your stamps to instantiate something different to the regular objects. The default algorithm is simply the Object.create
.
;let counter = 0;const compose = ;
assign
You can also override the Object.assign
implementation. But it is used in many various places. Beware!
;let counter = 0;const compose = ;
merge
You can also override the stamp-specific deep merge implementation. But it is used in many various places. Beware!
;let counter = 0;const compose = ;
Example
All the stamps created from this compose
functions are going to:
- have new
toString()
method which returns the stamp dummy name - print the name of the stamp each time it is composed
- count the number of descriptors merged and stamps instantiated
from 'make-compose';const counters = composedDescriptors: 0 createdStamps: 0;const compose = ;