Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / new-forms / OneForm / OneFormState.tsx
Size: Mime:
import { InputState } from '../inputs/InputState'
import { InputConfig } from '../inputs/typings'
import { FormState } from '../forms'
// @todo maybe put in forms?s
import { toFormState } from './toFormState'

/**
 * @todo how do we adapt the form state here...
 */
export class OneFormState<Generic = any> {
  store = new Map()

  // @todo and typings for compat, with depreciations and warnings
  setInputsList(inputsList: InputConfig[]) {
    // trigger getter, though this should be an action if it was not compat
    this.inputsList = inputsList
    return this
  }

  /**
   * @todo need to solve different types here
   * https://github.com/Microsoft/TypeScript/issues/2521
   */
  set inputsList(inputsList: InputConfig[]) {
    const formState = toFormState(inputsList)
    this.store.set('inputsConfigList', inputsList)
    this.store.set('inputsList', formState.inputsList)
    this.store.set('formState', formState)
  }
  /**
   * note that this MUST have same return type as setter
   * but we always return inputState so we use `as`
   */
  get inputsList(): InputState[] {
    return this.store.get('inputsList') as InputState[]
  }
  get formState(): FormState {
    return this.store.get('formState')
  }

  // extending without extending
  get: typeof FormState.prototype.get
  toJSON: typeof FormState.prototype.toJSON
}
OneFormState.prototype.get = FormState.prototype.get
OneFormState.prototype.toJSON = FormState.prototype.toJSON