lib/index.js
function PossibleStates(...allStates) {
  if (!allStates.length === 0) {
    throw Error('No values passed when constructing a new PossibleStates')
  }

  const containsData = typeDefinition => typeDefinition.match(/<.*>/)

  if (allStates[0].match(/<.*>/)) {
    throw Error('The initial state cannot contain data')
  }

  const parsedStates = allStates.map(state => {
    if (!containsData(state)) {
      return {name: state, data: []}
    }

    const [name, typeDefs] = state.match(/^(.*)<(.*)>$/).slice(1)

    return {name, data: typeDefs.split(',').map(def => def.trim())}
  })

  return PossibleStatesContainer({current: parsedStates[0], allStates: parsedStates})
}
function PossibleStates(...allStates) {
  if (!allStates.length === 0) {
    throw Error('No values passed when constructing a new PossibleStates')
  }

  const containsData = typeDefinition => typeDefinition.match(/<.*>/)

  if (allStates[0].match(/<.*>/)) {
    throw Error('The initial state cannot contain data')
  }

  const parsedStates = allStates.map(state => {
    if (!containsData(state)) {
      return {name: state, data: []}
    }

    const [name, typeDefs] = state.match(/^(.*)<(.*)>$/).slice(1)

    return {name, data: typeDefs.split(',').map(def => def.trim())}
  })

  return PossibleStatesContainer({current: parsedStates[0], allStates: parsedStates})
}
function PossibleStates ( ... allStates ) { if ( ! allStates . length === 0 ) { throw Error ( 'No values passed when constructing a new PossibleStates' ) } const containsData = typeDefinition => typeDefinition . match ( / <.*> / ) if ( allStates [ 0 ] . match ( / <.*> / ) ) { throw Error ( 'The initial state cannot contain data' ) } const parsedStates = allStates . map ( state => { if ( ! containsData ( state ) ) { return { name : state , data : [ ] } } const [ name , typeDefs ] = state . match ( / ^(.*)<(.*)>$ / ) . slice ( 1 ) return { name , data : typeDefs . split ( ',' ) . map ( def => def . trim ( ) ) } } ) return PossibleStatesContainer ( { current : parsedStates [ 0 ] , allStates : parsedStates } ) }
A function to parse the users definition and create
the corresponding Container.
The only exposed function to users.
A function to parse the users definition and create the corresponding Container . The only exposed function to users .