diff --git a/src/client/components/types/steps.jsx b/src/client/components/types/steps.jsx index bb1c20d..6cd7c09 100644 --- a/src/client/components/types/steps.jsx +++ b/src/client/components/types/steps.jsx @@ -19,7 +19,7 @@ const Steps = (props) => { else { stepsList = contextStepsList( context, - value.steps ? typeFromSteps(context, value.steps) : typeFromLiteral(value.value), + value.steps ? typeFromSteps(context, value.steps) : typeFromLiteral(value), ); } return ( @@ -67,7 +67,7 @@ const Steps = (props) => { type={ arg.steps ? typeFromSteps(context, arg.steps) - : typeFromLiteral(arg.value) + : typeFromLiteral(arg) } value={arg} /> diff --git a/src/client/components/types/typing.js b/src/client/components/types/typing.js index 3d450e3..953e93b 100644 --- a/src/client/components/types/typing.js +++ b/src/client/components/types/typing.js @@ -1,23 +1,30 @@ import {Context} from '@avocado/behavior' export function typeFromLiteral(v) { - if ('undefined' === typeof v) { - return 'undefined'; + console.log('tfl', v); + if ('literal' === v.type) { + const {value} = v; + if ('undefined' === typeof value) { + return 'undefined'; + } + if (null === value) { + return 'null'; + } + if ('number' === typeof value) { + return 'number'; + } + if ('string' === typeof value) { + return 'string'; + } + if ('boolean' === typeof value) { + return 'bool'; + } + if (value.length && 2 === value.length && value instanceof Array) { + return 'vector'; + } } - if (null === v) { - return 'null'; - } - if ('number' === typeof v) { - return 'number'; - } - if ('string' === typeof v) { - return 'string'; - } - if ('boolean' === typeof v) { - return 'bool'; - } - if (v.length && 2 === v.length && v instanceof Array) { - return 'vector'; + if ('actions' === v.type && v.traversals) { + return 'actions'; } return 'object'; } diff --git a/src/client/components/types/value.type-renderer.jsx b/src/client/components/types/value.type-renderer.jsx index 29d928e..93c43a2 100644 --- a/src/client/components/types/value.type-renderer.jsx +++ b/src/client/components/types/value.type-renderer.jsx @@ -13,12 +13,28 @@ import String from './string.type-renderer'; import {contextStepsList} from './steps-lists'; import {typeFits, typeFromSteps} from './typing'; +let TypeRenderers; +const ensureTypeRenderers = () => { + if (!TypeRenderers) { + const {all: allTypeRenderers} = require('./type-renderers.scwp'); + TypeRenderers = Object.values(allTypeRenderers()).reduce((r, M) => { + const {default: {type, component}} = M; + return {...r, [type]: component}; + }, {}); + } +}; + const renderValue = (context, type, value) => { + ensureTypeRenderers(); switch (value.type) { case 'traversal': { return ; } - case 'literal': + case 'actions': { + const Component = TypeRenderers['actions']; + return ; + } + case 'literal': { const stepsList = contextStepsList(context, type); const tierOptions = Object.keys(stepsList.reduce((r, optionSteps) => { if (!optionSteps[0] || !optionSteps[0].key) { @@ -39,23 +55,28 @@ const renderValue = (context, type, value) => { { (() => { - switch (type) { - case 'bool': - return ; - case 'number': - return ; - case 'any': - case 'string': - return ; - case 'object': - return ; - default: - return null; - } + const Component = TypeRenderers[type]; + return Component + ? + : null; + // switch (type) { + // case 'bool': + // return ; + // case 'number': + // return ; + // case 'any': + // case 'string': + // return ; + // case 'object': + // return ; + // default: + // return null; + // } })() } ); + } default: return null; }