Major leap forward
Differences with Stampit v2.
- node.js <= v0.12 and IE <= v10 maintenance period has ended (node, IE). WARNING! If running in node.js <= v0.12 or IE <= 11 then you'd need to polyfill the
Object.assign
. Like this, or that (autodetected). - Stamps from stampit v2 and stampit v3 are not compatible. You should not compose them together.
- Initializers now receive two arguments instead of just one.
First is the factory first argument (i.e.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);
- The factory first argument properties are no longer automatically assigned to the instance.
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"}
- A stamp's metadata is now stored in the
stamp.compose
object. Previously it was stored instamp.fixed
object. - Removed
convertConstructor()
. We plan to revive it and support the ES6 classes. - The
.props()
does not deeply merge objects any more, but shallow assigns properties. Just like.properties()
and.refs()
.
Use.deepProps()
instead. - Removed
state()
. Useprops()
instead. stampit.mixin()
,.extend()
,.mixIn()
,.assign()
are all gone too. Use ES6Object.assign()
static()
got renamed tostatics()
- The
stampit.isStamp
was moved. You should import it separately now:require('stampit/isStamp')
. - Initializers do not support Promises anymore. Meaning that "thenables" are not automatically unwrapped by initializers.
- The
stamp.init()
andstampit.init()
do not support objects as incoming arguments anymore. Use ES6.init(Object.values(obj))
instead.
New features
- Stampit is compatible with the Stamp Specification.
- You can import shortcuts and utility functions in various ways:
import {statics} from 'stampit'
const {statics} = require('stampit')
- New utility function
isComposable
. Can be imported separately:require('stampit/isComposable')
. - New utility function
compose
. It is the pure standardcompose
function implementation. Can be imported separately:require('stampit/compose')
. - New methods on stamps (
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