lib/index.js
function PossibleStatesContainer({current, allStates, data}) {
  return {
    caseOf(clauses) {
      const casesCovered = Object.keys(clauses)
      const notCovered = allStates.map(({name}) => name).filter(state => !casesCovered.includes(state))

      if (notCovered.length > 0 && !casesCovered.includes('_')) {
        throw Error('All cases are not covered in a "caseOf" clause')
      }

      const cb = clauses[current.name] || clauses['_']

      return cb instanceof Function ? cb(data) : cb
    },

    current() {
      return current.name
    },

    data() {
      return {...data}
    },

    ...generateTransitionHelpers(current, allStates),
    ...generateWhenAndNotHelpers(current, data, allStates),
  }
}
function PossibleStatesContainer({current, allStates, data}) {
  return {
    caseOf(clauses) {
      const casesCovered = Object.keys(clauses)
      const notCovered = allStates.map(({name}) => name).filter(state => !casesCovered.includes(state))

      if (notCovered.length > 0 && !casesCovered.includes('_')) {
        throw Error('All cases are not covered in a "caseOf" clause')
      }

      const cb = clauses[current.name] || clauses['_']

      return cb instanceof Function ? cb(data) : cb
    },

    current() {
      return current.name
    },

    data() {
      return {...data}
    },

    ...generateTransitionHelpers(current, allStates),
    ...generateWhenAndNotHelpers(current, data, allStates),
  }
}
function PossibleStatesContainer ( { current , allStates , data } ) { return { caseOf ( clauses ) { const casesCovered = Object . keys ( clauses ) const notCovered = allStates . map ( ( { name } ) => name ) . filter ( state => ! casesCovered . includes ( state ) ) if ( notCovered . length > 0 && ! casesCovered . includes ( '_' ) ) { throw Error ( 'All cases are not covered in a "caseOf" clause' ) } const cb = clauses [ current . name ] || clauses [ '_' ] return cb instanceof Function ? cb ( data ) : cb } , current ( ) { return current . name } , data ( ) { return { ... data } } , ... generateTransitionHelpers ( current , allStates ) , ... generateWhenAndNotHelpers ( current , data , allStates ) , } }
The main data structure passed to the clients.
The main data structure passed to the clients .