Repository URL to install this package:
|
Version:
3.5.4-es ▾
|
import { isObj, isArray } from 'exotic';
import { FormState } from '../forms';
import { OneFormState } from './OneFormState';
/**
* @todo renderProps
*/
export function fromObserverFormPropsToState(props) {
const obj = {
state: props.state,
inputsList: props.inputsList,
};
if (!isObj(props.state) && !isArray(props.inputsList)) {
throw new TypeError('cannot use @skava/form without .inputsList &| .state props!');
}
else if (isObj(props.state) && !isArray(props.state.inputsList)) {
throw new TypeError('using @skava/form without inputsList');
}
else if (props.state instanceof OneFormState) {
// @todo may need to make it into a `FormState` instead
// obj.state = props.state.formState || props.state
const { formState } = props.state;
obj.state = formState;
// could check inputs length is diff, then update
}
else if (props.state instanceof FormState) {
// not really needing to check this since I moved the default above
obj.state = props.state;
}
else {
throw new TypeError('why using @skava/form without FormState?');
}
return obj;
}
//# sourceMappingURL=fromObserverFormPropsToState.js.map