2.0.0 • Published 2 years ago

statee v2.0.0

Weekly downloads
2
License
WTFPL
Repository
github
Last release
2 years ago

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.

2.0.0

2 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago