fix: step cycles
This commit is contained in:
parent
7c7ac9eb40
commit
f483df3bb4
|
@ -9,7 +9,7 @@ const decorate = compose(
|
||||||
contempo(require('./entity.raw.scss')),
|
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 EntityComponent = (props) => {
|
||||||
const entity = new Entity(json);
|
const entity = new Entity(json);
|
||||||
|
|
|
@ -4,8 +4,11 @@ import {Traversal} from '@avocado/behavior/item/traversal';
|
||||||
|
|
||||||
import {typeFits} from './typing';
|
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 = [];
|
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});
|
||||||
}
|
}
|
||||||
|
@ -21,15 +24,22 @@ export const variableStepsList = (context, previousSteps, key, variable, variabl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const sublists = Object.entries(description)
|
const sublists = Object.entries(description)
|
||||||
.map(([key, description]) => (
|
.map(([nextKey, description]) => (
|
||||||
variableStepsList(
|
(
|
||||||
context,
|
// Cycle killer
|
||||||
previousSteps.concat(steps),
|
variableType === description.type
|
||||||
key,
|
&& variableType !== type
|
||||||
('object' === typeof variable && null !== variable) ? variable[key] : undefined,
|
|
||||||
description.type,
|
|
||||||
type
|
|
||||||
)
|
)
|
||||||
|
? []
|
||||||
|
: variableStepsList(
|
||||||
|
context,
|
||||||
|
previousSteps.concat(steps),
|
||||||
|
nextKey,
|
||||||
|
('object' === typeof variable && null !== variable) ? variable[nextKey] : undefined,
|
||||||
|
description.type,
|
||||||
|
type,
|
||||||
|
maxDepth - 1,
|
||||||
|
)
|
||||||
))
|
))
|
||||||
.map((childLists) => (
|
.map((childLists) => (
|
||||||
childLists.map((stepsList) => (
|
childLists.map((stepsList) => (
|
||||||
|
@ -41,11 +51,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) => (
|
export const contextStepsList = (context, type, maxDepth) => (
|
||||||
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)
|
variableStepsList(context, [{type: 'key', key}], key, variable, variableType, type, maxDepth)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
.filter((stepsList) => stepsList.length > 0)
|
.filter((stepsList) => stepsList.length > 0)
|
||||||
|
|
|
@ -12,16 +12,15 @@ const decorate = compose(
|
||||||
|
|
||||||
const Steps = (props) => {
|
const Steps = (props) => {
|
||||||
const {context, steps, type, value} = props;
|
const {context, steps, type, value} = props;
|
||||||
let stepsList;
|
const stepsList = contextStepsList(
|
||||||
if ('undefined' === typeof value) {
|
context,
|
||||||
stepsList = contextStepsList(context, type);
|
'undefined' === typeof value
|
||||||
}
|
? type
|
||||||
else {
|
: value.steps
|
||||||
stepsList = contextStepsList(
|
? typeFromSteps(context, value.steps)
|
||||||
context,
|
: typeFromLiteral(value),
|
||||||
value.steps ? typeFromSteps(context, value.steps) : typeFromLiteral(value),
|
steps.length + 2
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="steps">
|
<div className="steps">
|
||||||
{steps.map((step, i) => {
|
{steps.map((step, i) => {
|
||||||
|
|
|
@ -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);
|
const stepsList = contextStepsList(context, type, 3);
|
||||||
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