refactor: Op
This commit is contained in:
parent
c4ba6b118f
commit
082ddd1c81
|
@ -1,10 +1,11 @@
|
||||||
import {join} from 'path';
|
import {join} from 'path';
|
||||||
|
|
||||||
import {isKey} from '@avocado/behavior';
|
import {isInvocation, isKey} from '@avocado/behavior';
|
||||||
import {PropTypes, React} from '@latus/react';
|
import {PropTypes, React} from '@latus/react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
|
||||||
import Op from './expression/op';
|
import Invocation from './expression/invocation';
|
||||||
|
import Key from './expression/key';
|
||||||
|
|
||||||
const Expression = ({
|
const Expression = ({
|
||||||
context,
|
context,
|
||||||
|
@ -19,25 +20,40 @@ const Expression = ({
|
||||||
// eslint-disable-next-line react/destructuring-assignment
|
// eslint-disable-next-line react/destructuring-assignment
|
||||||
let description = context.constructor.descriptionFor(walk);
|
let description = context.constructor.descriptionFor(walk);
|
||||||
do {
|
do {
|
||||||
Ops.push(
|
const op = ops[i];
|
||||||
<Op
|
const opKey = JSON.stringify(op);
|
||||||
description={description}
|
const opPath = join(path, 'ops', Ops.length.toString());
|
||||||
context={context}
|
if (isKey(op)) {
|
||||||
Expression={Expression}
|
Ops.push(
|
||||||
key={JSON.stringify(ops[i])}
|
<Key
|
||||||
op={ops[i]}
|
description={description}
|
||||||
path={join(path, 'ops', Ops.length.toString())}
|
key={opKey}
|
||||||
/>,
|
op={op}
|
||||||
);
|
path={opPath}
|
||||||
if (isKey(ops[i])) {
|
/>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isInvocation(op)) {
|
||||||
|
Ops.push(
|
||||||
|
<Invocation
|
||||||
|
context={context}
|
||||||
|
description={description}
|
||||||
|
Expression={Expression}
|
||||||
|
key={opKey}
|
||||||
|
op={op}
|
||||||
|
path={opPath}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (isKey(op)) {
|
||||||
if (context === walk) {
|
if (context === walk) {
|
||||||
[walk] = context.get(ops[i].key);
|
[walk] = context.get(op.key);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
walk = walk[ops[i].key];
|
walk = walk[op.key];
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
...description.children[ops[i].key],
|
...description.children[op.key],
|
||||||
...context.constructor.descriptionFor(walk),
|
...context.constructor.descriptionFor(walk),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
import {
|
|
||||||
isInvocation,
|
|
||||||
isKey,
|
|
||||||
} from '@avocado/behavior';
|
|
||||||
import {PropTypes, React} from '@latus/react';
|
|
||||||
|
|
||||||
import Invocation from './invocation';
|
|
||||||
import Key from './key';
|
|
||||||
|
|
||||||
const Op = ({
|
|
||||||
context,
|
|
||||||
description,
|
|
||||||
Expression,
|
|
||||||
op,
|
|
||||||
path,
|
|
||||||
}) => (
|
|
||||||
<div className="op">
|
|
||||||
{isKey(op) && (
|
|
||||||
<Key
|
|
||||||
description={description}
|
|
||||||
op={op}
|
|
||||||
path={path}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{isInvocation(op) && (
|
|
||||||
<Invocation
|
|
||||||
context={context}
|
|
||||||
description={description}
|
|
||||||
Expression={Expression}
|
|
||||||
op={op}
|
|
||||||
path={path}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
Op.propTypes = {
|
|
||||||
context: PropTypes.shape({}).isRequired,
|
|
||||||
description: PropTypes.shape({}).isRequired,
|
|
||||||
Expression: PropTypes.func.isRequired,
|
|
||||||
op: PropTypes.shape({
|
|
||||||
key: PropTypes.string,
|
|
||||||
}).isRequired,
|
|
||||||
path: PropTypes.string.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Op;
|
|
Loading…
Reference in New Issue
Block a user