diff --git a/src/client/components/entity.jsx b/src/client/components/entity.jsx index 40c2329..29564b6 100644 --- a/src/client/components/entity.jsx +++ b/src/client/components/entity.jsx @@ -9,7 +9,7 @@ const decorate = compose( contempo(require('./entity.raw.scss')), ); -const json = require('~/../fixtures/rock-projectile.entity.json'); +const json = require('~/../fixtures/mama-kitty.entity.json'); const EntityComponent = (props) => { const entity = new Entity(json); diff --git a/src/client/components/types/steps-lists.js b/src/client/components/types/steps-lists.js index d0fd7f3..a85d662 100644 --- a/src/client/components/types/steps-lists.js +++ b/src/client/components/types/steps-lists.js @@ -4,8 +4,11 @@ import {Traversal} from '@avocado/behavior/item/traversal'; import {typeFits} from './typing'; -export const variableStepsList = (context, previousSteps, key, variable, variableType, type) => { +export const variableStepsList = (context, previousSteps, key, variable, variableType, type, maxDepth) => { const steps = []; + if (0 === maxDepth) { + return [steps]; + } if (typeFits(type, variableType)) { steps.push({type: 'key', key}); } @@ -21,15 +24,22 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl } } const sublists = Object.entries(description) - .map(([key, description]) => ( - variableStepsList( - context, - previousSteps.concat(steps), - key, - ('object' === typeof variable && null !== variable) ? variable[key] : undefined, - description.type, - type + .map(([nextKey, description]) => ( + ( + // Cycle killer + variableType === description.type + && variableType !== type ) + ? [] + : variableStepsList( + context, + previousSteps.concat(steps), + nextKey, + ('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined, + description.type, + type, + maxDepth - 1, + ) )) .map((childLists) => ( childLists.map((stepsList) => ( @@ -41,11 +51,11 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl return sublists.length > 0 ? [steps].concat(flatten(sublists)) : [steps]; }; -export const contextStepsList = (context, type) => ( +export const contextStepsList = (context, type, maxDepth) => ( flatten( Object.entries(context.all()) .map(([key, [variable, variableType]]) => ( - variableStepsList(context, [{type: 'key', key}], key, variable, variableType, type) + variableStepsList(context, [{type: 'key', key}], key, variable, variableType, type, maxDepth) )) ) .filter((stepsList) => stepsList.length > 0) diff --git a/src/client/components/types/steps.jsx b/src/client/components/types/steps.jsx index f100797..38b07af 100644 --- a/src/client/components/types/steps.jsx +++ b/src/client/components/types/steps.jsx @@ -12,16 +12,15 @@ const decorate = compose( const Steps = (props) => { const {context, steps, type, value} = props; - let stepsList; - if ('undefined' === typeof value) { - stepsList = contextStepsList(context, type); - } - else { - stepsList = contextStepsList( - context, - value.steps ? typeFromSteps(context, value.steps) : typeFromLiteral(value), - ); - } + const stepsList = contextStepsList( + context, + 'undefined' === typeof value + ? type + : value.steps + ? typeFromSteps(context, value.steps) + : typeFromLiteral(value), + steps.length + 2 + ); return (
{steps.map((step, i) => { diff --git a/src/client/components/types/value.type-renderer.jsx b/src/client/components/types/value.type-renderer.jsx index 93c43a2..0a4231a 100644 --- a/src/client/components/types/value.type-renderer.jsx +++ b/src/client/components/types/value.type-renderer.jsx @@ -35,7 +35,7 @@ const renderValue = (context, type, value) => { return ; } case 'literal': { - const stepsList = contextStepsList(context, type); + const stepsList = contextStepsList(context, type, 3); const tierOptions = Object.keys(stepsList.reduce((r, optionSteps) => { if (!optionSteps[0] || !optionSteps[0].key) { return r;