import * as React from 'react' import {isUndefined} from 'lodash-es' import {StringIndexedObject} from '../ts-helper' import {safeInvoke} from '../help' import {codeWarningOnce} from './warning' /** * @draft */ export function deprecatedProp(since: string, hint: string) { return ( props: StringIndexedObject, propName: string, componentName: string // location: string, // propFullName: string | null, ) => ( isUndefined(props[propName]) ? null : new Error(`[${componentName}] prop \`${propName}\` has been deprecated since ${since}. ${hint}`) ) } /** * @draft */ export function deprecatedMethod( compInstance: React.Component, methodName: string, since: string, hint: string, originMethod?: () => MethodResult ) { codeWarningOnce(false, [ `[${(compInstance.constructor as React.ComponentClass).displayName!}]`, `method \`${methodName}\` has been deprecated since ${since}.`, hint, ].join(' ')) return safeInvoke(originMethod) } export function getDeprecatedPropValue(propValue?: T, deprecatePropValue?: T) { return isUndefined(deprecatePropValue) ? propValue : deprecatePropValue }