Skip to content

Releases: pelotom/unionize

v1.0.0

03 Dec 22:09
Compare
Choose a tag to compare

Improved match performance.

v0.4.1

30 Aug 22:57
Compare
Choose a tag to compare

Adds support for avoiding conflicts where possible between tag name and underlying representation when using merged unions.

v0.4.0

30 Aug 07:50
Compare
Choose a tag to compare

Typecasting via as

Downcast an element of a union to a specific variant:

const { id, text } = Action.as.ADD_TODO(someAction) // throws if someAction is not an ADD_TODO

Payload properties are merged by default

By default now, the "payload" of a union variant is not put into a separate field but is merged into the same object that contains the tag. That is, instead of having variants of the form

{ tag: 'foo'; value: { x: number; y: boolean } }

we have

{ tag: 'foo'; x: number; y: boolean }

by default. This is strictly more general in what it can express. You can still recover the old behavior by specifying a valProp when you call unionize. The reason for this change is that it makes it much nicer to use unionize to define props for React components in which "invalid states are unrepresentable".

v0.3.0

28 Aug 01:43
Compare
Choose a tag to compare

The unionize function has been overloaded to allow providing optional tagProp and valProp arguments, supersedingunionizeCustom which is no longer exported.

v0.2.0

27 Aug 23:48
Compare
Choose a tag to compare

Fixed #3 by changing the API to require a value of the record type to be passed in when unionizing. As an example, what was before

const Foo = unionize<{
  x: number
  y: boolean
}>()

becomes

const Foo = unionize({
  x: ofType<number>(),
  y: ofType<boolean>(),
})

Slightly more verbose, but it has the advantage of being faster, more universally supported, and because the tags are now enumerable you can do things like directly pass the result of a unionize call to Redux' bindActionCreators.