feat: cycle

This commit is contained in:
cha0s 2020-06-20 07:35:55 -05:00
parent eb30c58157
commit 20fac9423e
3 changed files with 16 additions and 23 deletions

View File

@ -4,11 +4,8 @@ import {Traversal} from '@avocado/behavior/item/traversal';
import {typeFits} from './typing';
export const variableStepsList = (context, previousSteps, key, variable, variableType, type, maxDepth) => {
export const variableStepsList = (context, previousSteps, key, variable, variableType, type, isFinal) => {
const steps = [];
if (0 === maxDepth) {
return [steps];
}
if (typeFits(type, variableType)) {
steps.push({type: 'key', key});
}
@ -23,23 +20,20 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl
steps.push({type: 'invoke', args: []});
}
}
if (isFinal) {
return [steps];
}
const sublists = Object.entries(description)
.map(([nextKey, description]) => (
(
// Cycle killer
variableType === description.type
&& variableType !== type
.map(([nextKey, newDescription]) => (
variableStepsList(
context,
previousSteps.concat(steps),
nextKey,
('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined,
newDescription.type,
type,
newDescription.cycle,
)
? []
: variableStepsList(
context,
previousSteps.concat(steps),
nextKey,
('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined,
description.type,
type,
maxDepth - 1,
)
))
.map((childLists) => (
childLists.map((stepsList) => (
@ -51,11 +45,11 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl
return sublists.length > 0 ? [steps].concat(flatten(sublists)) : [steps];
};
export const contextStepsList = (context, type, maxDepth) => (
export const contextStepsList = (context, type) => (
flatten(
Object.entries(context.all())
.map(([key, [variable, variableType]]) => (
variableStepsList(context, [{type: 'key', key}], key, variable, variableType, type, maxDepth)
variableStepsList(context, [{type: 'key', key}], key, variable, variableType, type, false)
))
)
.filter((stepsList) => stepsList.length > 0)

View File

@ -19,7 +19,6 @@ const Steps = (props) => {
: value.steps
? typeFromSteps(context, value.steps)
: typeFromLiteral(value),
steps.length + 2
);
return (
<div className="steps">

View File

@ -35,7 +35,7 @@ const renderValue = (context, type, value) => {
return <Component context={context} value={value} />;
}
case 'literal': {
const stepsList = contextStepsList(context, type, 3);
const stepsList = contextStepsList(context, type);
const tierOptions = Object.keys(stepsList.reduce((r, optionSteps) => {
if (!optionSteps[0] || !optionSteps[0].key) {
return r;