Skip to content

Commit

Permalink
now interface doesn't filter additional props when props contain a …
Browse files Browse the repository at this point in the history
…struct, fix gcanti#245 (gcanti#246)
  • Loading branch information
gcanti authored Aug 17, 2016
1 parent 77ec487 commit 836fb3e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,34 @@
**Note**: Gaps between patch versions are faulty/broken releases.
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

# 3.2.11
# v3.2.12

- **Bug Fix**
- now `interface` doesn't filter additional props when props contain a struct, fix #245 (@gcanti)

# v3.2.11

- **Bug Fix**
- allow declare'd unions with custom dispatch, fix #242 (@gcanti)

# 3.2.10
# v3.2.10

- **Bug Fix**
- handle nully values in interface `is` function (@gcanti)

# 3.2.9
# v3.2.9

- **New Feature**
- fromJSON: track error path, fix #235 (@gcanti)
- **Internal**
- change shallow copy in order to improve perfs (@gcanti)

# 3.2.8
# v3.2.8

- **Bug Fix**
- mixing types and classes in a union throws, fix #232 (@gcanti)

# 3.2.7
# v3.2.7

- **Bug Fix**
- add support for class constructors, `fromJSON` module (@gcanti)
Expand Down
8 changes: 8 additions & 0 deletions lib/assign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function assign(x, y) {
for (var k in y) {
x[k] = y[k];
}
return x;
}

module.exports = assign;
3 changes: 2 additions & 1 deletion lib/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var getDefaultInterfaceName = require('./getDefaultInterfaceName');
var isIdentity = require('./isIdentity');
var is = require('./is');
var extend = require('./extend');
var assign = require('./assign');

function extendInterface(mixins, name) {
return extend(inter, mixins, name);
Expand Down Expand Up @@ -62,7 +63,7 @@ function inter(props, options) {
}

var idempotent = true;
var ret = {};
var ret = identity ? {} : assign({}, value);
for (var prop in props) {
var expected = props[prop];
var actual = value[prop];
Expand Down
7 changes: 2 additions & 5 deletions lib/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ var isObject = require('./isObject');
var isFunction = require('./isFunction');
var isArray = require('./isArray');
var isNumber = require('./isNumber');
var assign = require('./assign');

function getShallowCopy(x) {
if (isObject(x)) {
if (x instanceof Date || x instanceof RegExp) {
return x;
}
var ret = {};
for (var k in x) {
ret[k] = x[k];
}
return ret;
return assign({}, x);
}
if (isArray(x)) {
return x.concat();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tcomb",
"version": "3.2.11",
"version": "3.2.12",
"description": "Type checking and DDD for JavaScript",
"main": "index.js",
"typings": "index.d.ts",
Expand Down
11 changes: 11 additions & 0 deletions test/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ describe('t.interface(props, [name])', function () {
it('should hydrate fields', function () {
var hi = HydrateInterface({ point: { x: 0, y: 1} });
assert.equal(Point.is(hi.point), true);
var A = t.struct({ x: t.Number });
var B = t.inter({ a: A });
var actual = B({
a: { x: 1 },
extra: 3
});
assert.equal(actual.a instanceof A, true);
assert.deepEqual(actual, {
a: { x: 1 },
extra: 3
});
});

it('should handle strict option', function () {
Expand Down

0 comments on commit 836fb3e

Please sign in to comment.