From 0bd6a484e86048d54e0145d463683ea4032fa037 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Wed, 6 Nov 2019 14:44:03 +0800 Subject: [PATCH] Docgen extractor: Minor housecleaning --- addons/docs/src/lib/docgenUtils.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/docs/src/lib/docgenUtils.ts b/addons/docs/src/lib/docgenUtils.ts index 680abd49ba94..8bf6d15bfb26 100644 --- a/addons/docs/src/lib/docgenUtils.ts +++ b/addons/docs/src/lib/docgenUtils.ts @@ -5,7 +5,7 @@ import { getTypeSystemHandler, getPropTypeSystem } from './type-system-handlers' export type PropsExtractor = (component: Component) => PropsTableProps | null; -export type PropDefGetter = (type: Component, section: string) => PropDef[]; +export type PropDefGetter = (component: Component, section: string) => PropDef[]; export const str = (o: any) => { if (!o) { @@ -17,24 +17,24 @@ export const str = (o: any) => { throw new Error(`Description: expected string, got: ${JSON.stringify(o)}`); }; -export const hasDocgen = (obj: any) => !!obj.__docgenInfo; +export const hasDocgen = (component: Component) => !!component.__docgenInfo; -export const hasDocgenSection = (obj: any, section: string) => - obj.__docgenInfo && - obj.__docgenInfo[section] && - Object.keys(obj.__docgenInfo[section]).length > 0; +export const hasDocgenSection = (component: Component, section: string) => + component && + component.__docgenInfo && + component.__docgenInfo[section] && + Object.keys(component.__docgenInfo[section]).length > 0; -export const extractPropsFromDocgen: PropDefGetter = (type, section) => { - const props: Record = {}; - - const docgenInfo = type.__docgenInfo; - const docgenInfoProps = (docgenInfo && docgenInfo[section]) || {}; - const propKeys = Object.keys(docgenInfoProps); - if (propKeys.length === 0) { +export const extractPropsFromDocgen: PropDefGetter = (component, section) => { + if (!hasDocgenSection(component, section)) { return []; } - // Assuming the props for a given type will all have the same type system. + const props: Record = {}; + const docgenInfoProps = component.__docgenInfo[section]; + const propKeys = Object.keys(docgenInfoProps); + + // Assuming the props for a given component will all have the same type system. const typeSystem = getPropTypeSystem(docgenInfoProps[propKeys[0]]); const typeSystemHandler = getTypeSystemHandler(typeSystem);