Reorganize wrapComponents, fix CommonMark

This commit is contained in:
Kyle Shockey
2017-05-23 19:39:54 -07:00
parent 31abbb7641
commit 128b910d58
5 changed files with 37 additions and 1 deletions

View File

@@ -58,6 +58,7 @@
"react-height": "^2.0.0", "react-height": "^2.0.0",
"react-hot-loader": "1.3.1", "react-hot-loader": "1.3.1",
"react-immutable-proptypes": "2.1.0", "react-immutable-proptypes": "2.1.0",
"react-markdown": "^2.5.0",
"react-motion": "0.4.4", "react-motion": "0.4.4",
"react-object-inspector": "0.2.1", "react-object-inspector": "0.2.1",
"react-redux": "^4.x.x", "react-redux": "^4.x.x",

View File

@@ -0,0 +1,24 @@
import React from "react"
const SUPPORTED_OPENAPI_VERSIONS = ["3.0.0-rc0"]
export function isOAS3(jsSpec) {
return !!jsSpec.openapi && SUPPORTED_OPENAPI_VERSIONS.indexOf(jsSpec.openapi) > -1
}
export function OAS3ComponentWrapFactory(Component) {
return (Ori, system) => (props) => {
if(system && system.specSelectors && system.specSelectors.specJson) {
const spec = system.specSelectors.specJson().toJS()
if(isOAS3(spec)) {
return <Component {...props}></Component>
} else {
return <Ori {...props}></Ori>
}
} else {
console.warn("OAS3 wrapper: couldn't get spec")
return null
}
}
}

View File

@@ -1,13 +1,14 @@
// import reducers from "./reducers" // import reducers from "./reducers"
// import * as actions from "./actions" // import * as actions from "./actions"
import * as wrapSelectors from "./wrap-selectors" import * as wrapSelectors from "./wrap-selectors"
// import * as wrapActions from "./wrap-actions" import wrapComponents from "./wrap-components"
export default function() { export default function() {
return { return {
components: { components: {
}, },
wrapComponents,
statePlugins: { statePlugins: {
spec: { spec: {
// wrapActions, // wrapActions,

View File

@@ -0,0 +1,5 @@
import Markdown from "./markdown"
export default {
Markdown
}

View File

@@ -0,0 +1,5 @@
import React from "react"
import ReactMarkdown from "react-markdown"
import { OAS3ComponentWrapFactory } from "../helpers"
export default OAS3ComponentWrapFactory(({ source }) => <ReactMarkdown source={source} />)