Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose record tags as string constants #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GrzegorzKazana
Copy link

@GrzegorzKazana GrzegorzKazana commented Sep 27, 2020

Adresses #75 .

Motivation
When interfacing with other libraries/other code, there is sometimes a need for for using the tags from the tagged union. This results in need to define our unions as follows, which is unnecessarily verbose and boilerplateful.

const ON = 'ON';
const OFF = 'OFF';

const State = unionized({
  [ON]: ofType<{}>(),
  [OFF]: ofType<{}>()
})

// do something later with tag
console.log(ON)  // 'ON'

Solution
Expose record tags as a property on the Unionized object.

const State = unionized({
  ON: ofType<{}>(),
  OFF: ofType<{}>()
})

// do something later with tag
console.log(State.tags.ON)  // 'ON'

/*
State.tags is:
{
  ON: 'ON';
  OFF: 'OFF';
}
*/

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 046b830 on GrzegorzKazana:expose-tag-record into 55240dd on pelotom:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants