OOP is better with stamps: Composable object factories.
The v3.1.0
tarball was uploaded to NPM registry somewhat wrongly. This v3.1.1
just fixes the issue.
"Composers" is an experimental proposal to the Stamp Specification.
Composers are sort-of-a hooks where you can alter composition with your own logic. See this article.
Simplest example:
const Tracked = stampit()
.composers(({composables, stamp}) => { // declaring a composer
console.log(`Composed a stamp "${stamp}" from the following:
"${composable.join()}"`);
});
The list of composers is stored in the stamp.compose.configuration.composers
array. This means that stamps are still specification compatible.
Previous release accidentally published few unnecessary development files.
Object instance property access performance was 100 times lower than for plain objects. Fixed. Also, improved IDE support with some additional JSDoc.
By removing .babelrc
file, and the babel
property in the package.json
we improve compatibility with react-native and other packages which traverse the node_modules
for babel stuff.
Instead, we are using buble for transpilation. It's faster, and generates a tiny bit smaller bundle file (1.52KB vs 1.56KB).
Remove "browser" property from package.json as not needed and wrongly used
Stampit was exporting the original pure compose
function. Although, by design it should have exported the infected compose (aka stampit).
Reduced the NPM distributed tarball from 60KB to 43KB.
Differences with Stampit v2.
Object.assign
. Like this, or that (autodetected).arguments[0]
), second is the same options object as before - { instance, stamp, args }
.Stampit v2:
const Stamp = stampit({ init({instance, stamp, args}) {
// ...
}});
Stampit v3:
const Stamp = stampit({ init(arg, {instance, stamp, args}) {
console.log(arg); // 42
}});
Stamp(42);
Stampit v2:
const Stamp = stampit({ init({instance, stamp, args}) {
console.log(this); // {foo: "bar"}
}});
Stamp({foo: 'bar'});
Stampit v3:
const Stamp = stampit({init(arg, {instance, stamp, args}) {
console.log(this); // {}
}});
Stamp({foo: 'bar'});
A workaround can be implemented as a separate behavior (stamp).
const AssignFirstArgument = stampit({ init(opts) {
Object.assign(this, opts);
}});
Stamp = AssignFirstArgument.compose(Stamp);
Stamp({foo: 'bar'}); // {foo: "bar"}
stamp.compose
object. Previously it was stored in stamp.fixed
object.convertConstructor()
. We plan to revive it and support the ES6 classes..props()
does not deeply merge objects any more, but shallow assigns properties. Just like .properties()
and .refs()
.
Use .deepProps()
instead.state()
. Use props()
instead.stampit.mixin()
, .extend()
, .mixIn()
, .assign()
are all gone too. Use ES6 Object.assign()
static()
got renamed to statics()
stampit.isStamp
was moved. You should import it separately now: require('stampit/isStamp')
.stamp.init()
and stampit.init()
do not support objects as incoming arguments anymore. Use ES6 .init(Object.values(obj))
instead.New features
import {statics} from 'stampit'
const {statics} = require('stampit')
isComposable
. Can be imported separately: require('stampit/isComposable')
.compose
. It is the pure standard compose
function implementation. Can be imported separately: require('stampit/compose')
.stamp.METHOD
), as well as new shortcut methods on stampit (stampit.METHOD
), as well as new options to stampit (stampit({OPTION: *})
). They are: initializers
, init
, props
, properties
, deepProps
, deepProperties
, statics
, staticProperties
, deepStatics
, staticDeepProperties
, conf
, configuration
, deepConf
, deepConfiguration
, propertyDescriptors
, staticPropertyDescriptors
Generators were not considered as methods. Now they are. :)