Repository URL to install this package:
|
Version:
3.0.10 ▾
|
import { isSafe, isUndefined } from 'exotic'
import { InputChain } from './InputChain'
import { inputChains } from './config'
import { toggleTypes, validTypes, types } from './fixture'
import { ObserverInputProps } from './typings'
export const fromPropsToInputChain = (
props: ObserverInputProps
): InputChain => {
const isSatisfiedByProps = (chain: any): boolean => {
const isSatisfied = chain.isSatisfiedByProps(props)
console.log('isSatisfiedByProps: ', chain.name, isSatisfied)
return isSatisfied
}
const InputChainDecorator = inputChains.find(isSatisfiedByProps)
if (InputChainDecorator !== undefined) {
const instance = new InputChainDecorator()
return instance
}
if (process.env.NODE_ENV !== 'production') {
console.warn('[InputChain] fromPropsToInputChain COULD NOT FIND CHAIN')
console.dir(props)
throw new Error('could not find [InputChain]')
}
}
export const isVisible = (isHidden: boolean | undefined) =>
isUndefined(isHidden) || (isSafe(isHidden) && !isHidden)
// @todo @fixme @exotic dunno why
// if (hasOwnProp(types, key) === true) {
export const hasType = key => Object.prototype.hasOwnProperty.call(types, key)
/**
* @todo - this is used so we can depreciate the weird effects
* of making everything observable without defining it strictly
*/
export const unknown = (key: string, value: any) => {
// unknown
const msg = 'unknown data ' + JSON.stringify({ [key]: value })
// @todo - but not on server
// const unknown = new Error(msg)
// console.error(unknown)
// console.warn(msg)
}
export const shouldRemap = (key: string) => {
return key === 'identifier'
}