statee
v2.0.0
Published
Statee
Downloads
19
Readme
📬 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
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.