From 6fbd47b340ae2a458f8998d3e4f58d0a89822331 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 20 Nov 2017 15:02:35 +0200 Subject: [PATCH] Update Redoc Standalone API --- src/components/RedocStandalone.tsx | 13 +++---------- src/standalone.tsx | 10 +++++++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/RedocStandalone.tsx b/src/components/RedocStandalone.tsx index c28cdee2..41805c8d 100644 --- a/src/components/RedocStandalone.tsx +++ b/src/components/RedocStandalone.tsx @@ -8,7 +8,8 @@ import { ErrorBoundary } from './ErrorBoundary'; import { Redoc } from './Redoc/Redoc'; export interface RedocStandaloneProps { - specOrSpecUrl: string | object; + spec?: object; + specUrl?: string; options?: { theme?: ThemeInterface; }; @@ -16,15 +17,7 @@ export interface RedocStandaloneProps { export class RedocStandalone extends React.Component { render() { - const { specOrSpecUrl, options } = this.props; - let specUrl; - let spec; - - if (typeof specOrSpecUrl === 'string') { - specUrl = specOrSpecUrl; - } else if (typeof specOrSpecUrl === 'object') { - spec = specOrSpecUrl; - } + const { spec, specUrl, options } = this.props; return ( diff --git a/src/standalone.tsx b/src/standalone.tsx index 258311c7..ecf063cb 100644 --- a/src/standalone.tsx +++ b/src/standalone.tsx @@ -33,11 +33,19 @@ export function init( throw new Error('"element" argument is not provided and tag is not found on the page'); } + let specUrl, spec; + if (typeof specOrSpecUrl === 'string') { + specUrl = specOrSpecUrl; + } else if (typeof specOrSpecUrl === 'object') { + spec = specOrSpecUrl; + } + render( React.createElement( RedocStandalone, { - specOrSpecUrl, + spec, + specUrl, options: { ...options, ...parseOptionsFromElement(element) }, }, ['Loading...'],