feat: cycle
This commit is contained in:
parent
eb30c58157
commit
20fac9423e
|
@ -4,11 +4,8 @@ import {Traversal} from '@avocado/behavior/item/traversal';
|
||||||
|
|
||||||
import {typeFits} from './typing';
|
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 = [];
|
const steps = [];
|
||||||
if (0 === maxDepth) {
|
|
||||||
return [steps];
|
|
||||||
}
|
|
||||||
if (typeFits(type, variableType)) {
|
if (typeFits(type, variableType)) {
|
||||||
steps.push({type: 'key', key});
|
steps.push({type: 'key', key});
|
||||||
}
|
}
|
||||||
|
@ -23,22 +20,19 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl
|
||||||
steps.push({type: 'invoke', args: []});
|
steps.push({type: 'invoke', args: []});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isFinal) {
|
||||||
|
return [steps];
|
||||||
|
}
|
||||||
const sublists = Object.entries(description)
|
const sublists = Object.entries(description)
|
||||||
.map(([nextKey, description]) => (
|
.map(([nextKey, newDescription]) => (
|
||||||
(
|
variableStepsList(
|
||||||
// Cycle killer
|
|
||||||
variableType === description.type
|
|
||||||
&& variableType !== type
|
|
||||||
)
|
|
||||||
? []
|
|
||||||
: variableStepsList(
|
|
||||||
context,
|
context,
|
||||||
previousSteps.concat(steps),
|
previousSteps.concat(steps),
|
||||||
nextKey,
|
nextKey,
|
||||||
('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined,
|
('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined,
|
||||||
description.type,
|
newDescription.type,
|
||||||
type,
|
type,
|
||||||
maxDepth - 1,
|
newDescription.cycle,
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
.map((childLists) => (
|
.map((childLists) => (
|
||||||
|
@ -51,11 +45,11 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl
|
||||||
return sublists.length > 0 ? [steps].concat(flatten(sublists)) : [steps];
|
return sublists.length > 0 ? [steps].concat(flatten(sublists)) : [steps];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const contextStepsList = (context, type, maxDepth) => (
|
export const contextStepsList = (context, type) => (
|
||||||
flatten(
|
flatten(
|
||||||
Object.entries(context.all())
|
Object.entries(context.all())
|
||||||
.map(([key, [variable, variableType]]) => (
|
.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)
|
.filter((stepsList) => stepsList.length > 0)
|
||||||
|
|
|
@ -19,7 +19,6 @@ const Steps = (props) => {
|
||||||
: value.steps
|
: value.steps
|
||||||
? typeFromSteps(context, value.steps)
|
? typeFromSteps(context, value.steps)
|
||||||
: typeFromLiteral(value),
|
: typeFromLiteral(value),
|
||||||
steps.length + 2
|
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
<div className="steps">
|
<div className="steps">
|
||||||
|
|
|
@ -35,7 +35,7 @@ const renderValue = (context, type, value) => {
|
||||||
return <Component context={context} value={value} />;
|
return <Component context={context} value={value} />;
|
||||||
}
|
}
|
||||||
case 'literal': {
|
case 'literal': {
|
||||||
const stepsList = contextStepsList(context, type, 3);
|
const stepsList = contextStepsList(context, type);
|
||||||
const tierOptions = Object.keys(stepsList.reduce((r, optionSteps) => {
|
const tierOptions = Object.keys(stepsList.reduce((r, optionSteps) => {
|
||||||
if (!optionSteps[0] || !optionSteps[0].key) {
|
if (!optionSteps[0] || !optionSteps[0].key) {
|
||||||
return r;
|
return r;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user