-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: taggedUnion should handle sub unions / tagged unions correct…
…ly, closes #257 Experimental: optimize union with the same algorithm used in taggedUnion Also removed the following useless internal APIs - isTagged - findTagged - getTagValue
- Loading branch information
Showing
8 changed files
with
408 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,13 @@ | |
**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. | ||
|
||
# 1.6.1 | ||
|
||
- **Bug Fix** | ||
- `taggedUnion` should handle sub unions / tagged unions correctly, closes #257 (@gcanti) | ||
- **Experimental** | ||
- optimize `union` with the same algorithm used in `taggedUnion` (@gcanti) | ||
|
||
# 1.6.0 | ||
|
||
**Important**. This version requires `[email protected]+` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as Benchmark from 'benchmark' | ||
import * as t from '../src' | ||
|
||
const suite = new Benchmark.Suite() | ||
|
||
const A = t.intersection([ | ||
t.type({ | ||
type: t.literal('A') | ||
}), | ||
t.type({ | ||
bar: t.number | ||
}) | ||
]) | ||
const U1 = t.union([A, t.undefined]) | ||
const U2 = t.union([t.undefined, A]) | ||
|
||
suite | ||
.add('getIndexRecord (U1)', function() { | ||
t.getIndexRecord(U1.types) | ||
}) | ||
.add('getIndexRecord (U2)', function() { | ||
t.getIndexRecord(U2.types) | ||
}) | ||
.on('cycle', function(event: any) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function(this: any) { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as Benchmark from 'benchmark' | ||
import * as t from '../src' | ||
|
||
const suite = new Benchmark.Suite() | ||
|
||
const makeType = <L extends string>(L: L) => | ||
t.type( | ||
{ | ||
type: t.literal(L), | ||
a: t.string | ||
}, | ||
L | ||
) | ||
|
||
const T = t.union(['A', 'B', 'C', 'D', 'E'].map(makeType) as any) | ||
|
||
const valid = { type: 'E', a: 'a' } | ||
const invalid = { type: 'Z' } | ||
|
||
suite | ||
.add('union (decode) (valid)', function() { | ||
T.decode(valid) | ||
}) | ||
.add('union (decode) (invalid)', function() { | ||
T.decode(invalid) | ||
}) | ||
.add('union (encode) (valid)', function() { | ||
T.encode(valid) | ||
}) | ||
.add('union (create)', function() { | ||
t.union(['A', 'B', 'C', 'D', 'E'].map(makeType) as any) | ||
}) | ||
.on('cycle', function(event: any) { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', function(this: any) { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')) | ||
}) | ||
.run({ async: true }) |
Oops, something went wrong.