tcomb
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -15,2 +15,7 @@ # Changelog | ||
## v2.4.1 | ||
- **New Feature** | ||
- added struct multiple inheritance, fix #143 | ||
## v2.4.0 | ||
@@ -17,0 +22,0 @@ |
28
index.js
@@ -248,3 +248,3 @@ /*! @preserve | ||
assert(isString(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to irreducible(name, predicate) (expected a string)'; }); | ||
assert(isFunction(predicate), 'Invalid argument predicate supplied to irreducible(name, predicate)'); | ||
assert(isFunction(predicate), 'Invalid argument predicate ' + exports.stringify(predicate) + ' supplied to irreducible(name, predicate) (expected a function)'); | ||
} | ||
@@ -366,14 +366,18 @@ | ||
Struct.extend = function (structs, name) { | ||
structs = [].concat(structs).map(function (x, i) { | ||
if (isObject(x)) { | ||
return x; | ||
var props = {}; | ||
var prototype = {}; | ||
[Struct].concat(structs).forEach(function (struct, i) { | ||
if (isObject(struct)) { | ||
mixin(props, struct); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isStruct(x), function () { return 'Invalid argument structs[' + i + '] ' + exports.stringify(structs[i]) + ' supplied to ' + displayName + '.extend(structs, name)'; }); | ||
else { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isStruct(struct), function () { return 'Invalid argument structs[' + i + '] ' + exports.stringify(struct) + ' supplied to ' + displayName + '.extend(structs, name)'; }); | ||
} | ||
mixin(props, struct.meta.props); | ||
mixin(prototype, struct.prototype); | ||
} | ||
return x.meta.props; | ||
}); | ||
structs.unshift(props); | ||
var ret = struct(structs.reduce(mixin, {}), name); | ||
mixin(ret.prototype, Struct.prototype); // prototypal inheritance | ||
var ret = struct(props, name); | ||
mixin(ret.prototype, prototype); | ||
return ret; | ||
@@ -514,3 +518,3 @@ }; | ||
name = name || getDefaultMaybeName(type); | ||
var displayName = name || getDefaultMaybeName(type); | ||
@@ -530,3 +534,3 @@ function Maybe(value, path) { | ||
Maybe.displayName = name; | ||
Maybe.displayName = displayName; | ||
@@ -533,0 +537,0 @@ Maybe.is = function (x) { |
{ | ||
"name": "tcomb", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "Type checking and DDD for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,3 +16,3 @@ [![build status](https://img.shields.io/travis/gcanti/tcomb/master.svg?style=flat-square)](https://travis-ci.org/gcanti/tcomb) | ||
// a user defined type | ||
var Integer = t.subtype(t.Number, function (n) => { return n % 1 === 0; }, 'Integer'); // <= give a name for better debug messages | ||
var Integer = t.subtype(t.Number, function (n) { return n % 1 === 0; }, 'Integer'); // <= give a name for better debug messages | ||
@@ -171,2 +171,3 @@ // a struct | ||
* [typed-immutable](https://github.com/Gozala/typed-immutable) | ||
* [immu](https://github.com/scottcorgan/immu) | ||
@@ -173,0 +174,0 @@ * [immutable](https://github.com/facebook/immutable-js) |
57007
797
183