import { action , observable , toJS } from 'mobx' ; import { createContext } from 'react' ; import { WorkflowStep } from '../dist/workflow' ; import AbstractStore from './store' ; class CluiStore extends AbstractStore { @ observable cluiPlaceholder = '' ; @ observable inputMessage = '' ; @ observable isSubmitted = false ; @ observable chosenFeatures : Array < WorkflowStep > = [ ] ; @ observable configuration : { [ name ] : { value : any ; [ name ] : any ; } ; } = { } ; @ observable configurationJS = { } ; @ observable ran = false ; @ observable cluiToggle = true ; @ observable cluiFocused = false ; constructor ( ) { super ( ) ; this . init ( ) ; } @ action init = ( ) => { this . cluiPlaceholder = 'Hi, I am a clui!' ; this . inputMessage = '' ; this . isSubmitted = false ; this . chosenFeatures = [ ] ; this . configuration = { } ; this . configurationJS = { } ; } ; @ action updateCluiPlaceholder = ( newPlaceholder ) => { this . cluiPlaceholder = newPlaceholder ; } ; @ action setCluiFocused = ( state ) => { this . cluiFocused = state ; } ; @ action public setInputMessage = ( value ) => { this . inputMessage = value ; } ; @ action setSubmitStatus = ( value ) => { this . isSubmitted = value ; } ; param newChosenFeatures @ action updateChosenFeatures = ( newChosenFeatures ) => { if ( newChosenFeatures . length > 0 ) { this . chosenFeatures = newChosenFeatures ; } } ; param newConfiguration param parents @ action updateConfiguration = ( newConfiguration , inputParents ) => { const parents = [ ... inputParents ] ; const { configuration } = this ; function updateObject ( object ) { while ( parents . length > 1 ) { const key = parents . shift ( ) as string ; if ( ! ( key in object ) ) { object = Object . assign ( object , { [ key ] : { } } ) ; } object = object [ key ] ; } const key = parents . shift ( ) as string ; if ( key in object ) { object [ key ] = Object . assign ( object [ key ] , newConfiguration ) ; } else { object = Object . assign ( object , { [ key ] : newConfiguration } ) ; } } updateObject ( configuration ) ; this . configuration = configuration ; this . configurationJS = toJS ( configuration ) ; } ; @ action ( 'Update Ran' ) updateRun = ( value = true ) => { this . ran = value ; } ; @ action ( 'Update cluiToggle' ) updateCluiToggle = ( value = true ) => { this . cluiToggle = value ; } ; } const cluiStore = new CluiStore ( ) ; export default cluiStore ; export const CluiStoreContext = createContext ( cluiStore ) ;