Skip to content

Expose record tags as string constants#76

Open
GrzegorzKazana wants to merge 2 commits intopelotom:masterfrom
GrzegorzKazana:expose-tag-record
Open

Expose record tags as string constants#76
GrzegorzKazana wants to merge 2 commits intopelotom:masterfrom
GrzegorzKazana:expose-tag-record

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