diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-29 01:16:35 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-29 01:16:35 +0800 |
commit | 3472bdcfd4ea0a6145dd68972f563e483baf7e6b (patch) | |
tree | 6ed8d25cd58cd243aaf94af37f4e9d1d6a98fc85 /packages/website/ts/pages/documentation/method_signature.tsx | |
parent | 78f0ab36823127b67c1ea24b7245c51ba814b16a (diff) | |
download | dexon-0x-contracts-3472bdcfd4ea0a6145dd68972f563e483baf7e6b.tar.gz dexon-0x-contracts-3472bdcfd4ea0a6145dd68972f563e483baf7e6b.tar.zst dexon-0x-contracts-3472bdcfd4ea0a6145dd68972f563e483baf7e6b.zip |
Refactor docs to be more declarative, put all hard-coded doc-related data in one place so it easier to add new doc pages
Diffstat (limited to 'packages/website/ts/pages/documentation/method_signature.tsx')
-rw-r--r-- | packages/website/ts/pages/documentation/method_signature.tsx | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/packages/website/ts/pages/documentation/method_signature.tsx b/packages/website/ts/pages/documentation/method_signature.tsx index e3806b2fa..197252fb4 100644 --- a/packages/website/ts/pages/documentation/method_signature.tsx +++ b/packages/website/ts/pages/documentation/method_signature.tsx @@ -1,5 +1,6 @@ import * as _ from 'lodash'; import * as React from 'react'; +import {DocsInfo} from 'ts/pages/documentation/docs_info'; import {Type} from 'ts/pages/documentation/type'; import {Parameter, SolidityMethod, TypeDefinitionByName, TypescriptMethod} from 'ts/types'; @@ -8,6 +9,7 @@ interface MethodSignatureProps { shouldHideMethodName?: boolean; shouldUseArrowSyntax?: boolean; typeDefinitionByName?: TypeDefinitionByName; + docsInfo: DocsInfo; } const defaultProps = { @@ -16,45 +18,64 @@ const defaultProps = { }; export const MethodSignature: React.SFC<MethodSignatureProps> = (props: MethodSignatureProps) => { - const parameters = renderParameters(props.method, props.typeDefinitionByName); + const parameters = renderParameters(props.method, props.docsInfo, props.typeDefinitionByName); const paramString = _.reduce(parameters, (prev: React.ReactNode, curr: React.ReactNode) => { return [prev, ', ', curr]; }); const methodName = props.shouldHideMethodName ? '' : props.method.name; const typeParameterIfExists = _.isUndefined((props.method as TypescriptMethod).typeParameter) ? undefined : - renderTypeParameter(props.method, props.typeDefinitionByName); + renderTypeParameter(props.method, props.docsInfo, props.typeDefinitionByName); return ( <span> {props.method.callPath}{methodName}{typeParameterIfExists}({paramString}) {props.shouldUseArrowSyntax ? ' => ' : ': '} {' '} {props.method.returnType && - <Type type={props.method.returnType} typeDefinitionByName={props.typeDefinitionByName}/> + <Type + type={props.method.returnType} + typeDefinitionByName={props.typeDefinitionByName} + docsInfo={props.docsInfo} + /> } </span> ); }; -function renderParameters(method: TypescriptMethod|SolidityMethod, typeDefinitionByName?: TypeDefinitionByName) { +function renderParameters( + method: TypescriptMethod|SolidityMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName, +) { const parameters = method.parameters; const params = _.map(parameters, (p: Parameter) => { const isOptional = p.isOptional; + const t = ( + <Type + type={p.type} + typeDefinitionByName={typeDefinitionByName} + docsInfo={docsInfo} + /> + ); return ( <span key={`param-${p.type}-${p.name}`}> - {p.name}{isOptional && '?'}: <Type type={p.type} typeDefinitionByName={typeDefinitionByName}/> + {p.name}{isOptional && '?'}: {t} </span> ); }); return params; } -function renderTypeParameter(method: TypescriptMethod, typeDefinitionByName?: TypeDefinitionByName) { +function renderTypeParameter( + method: TypescriptMethod, docsInfo: DocsInfo, typeDefinitionByName?: TypeDefinitionByName, +) { const typeParameter = method.typeParameter; const typeParam = ( <span> {`<${typeParameter.name} extends `} - <Type type={typeParameter.type} typeDefinitionByName={typeDefinitionByName}/> + <Type + type={typeParameter.type} + typeDefinitionByName={typeDefinitionByName} + docsInfo={docsInfo} + /> {`>`} </span> ); |