Skip to content

porsager/statee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM version Size license

📬 statee

Like enums where each one can contain a value

Statee can help you make a quick state model with multiple grouped properties that are mutually exclusive, where each property can contain any value, and if one in the group is set, the others will return to their initial value.

Simple usage example

Live sample on flems.io

import statee from 'statee'

const state = statee({
  loading: false,
  result: null,
  error: null
})

state.loading = true
state.result = { some: 'result' } // state.loading === false
state.error = new Error('Oh noes - not good') // state.result === null

statee(...groups)

The Statee creator can take multiple arguments, where each will be a group of properties that become mutually exclusive.

statee.property = 'some value'

Setting one of the specified properties will set the rest to their initial value.

statee('property')

The statee instance itself is a function that returns a setter for any property passed to it. This is very useful if supplying it as a callback for promises and the like.

About

Mutually exclusive properties state object

Resources

License

Stars

Watchers

Forks

Packages

No packages published