refactor: varargs
This commit is contained in:
parent
b8fbd61765
commit
f7dc24f9d0
|
@ -15,9 +15,10 @@ import Variant from './variant';
|
|||
|
||||
const Expression = ({
|
||||
context,
|
||||
value,
|
||||
path,
|
||||
type,
|
||||
value,
|
||||
vararg,
|
||||
}) => {
|
||||
const latus = useLatus();
|
||||
const patch = useJsonPatcher();
|
||||
|
@ -60,7 +61,6 @@ const Expression = ({
|
|||
if (isKey(op)) {
|
||||
const isFirst = 0 === i;
|
||||
const isLast = i === ops.length - 1 ? true : isInvocation(ops[i + 1]);
|
||||
const isUndefined = 'undefined' === description.type || 'undefined' === type;
|
||||
Renderables.push(
|
||||
<Key
|
||||
childrenDescription={{
|
||||
|
@ -72,7 +72,7 @@ const Expression = ({
|
|||
: {}
|
||||
),
|
||||
...(
|
||||
isUndefined || (isLast && !isFirst)
|
||||
vararg || (isLast && !isFirst)
|
||||
? {'.': {label: '', type: description.type}}
|
||||
: {}
|
||||
),
|
||||
|
@ -94,7 +94,7 @@ const Expression = ({
|
|||
const parts = localPath.split('/');
|
||||
parts.pop();
|
||||
parts.pop();
|
||||
if (isUndefined) {
|
||||
if (vararg) {
|
||||
parts.pop();
|
||||
patch({
|
||||
op: 'remove',
|
||||
|
@ -297,8 +297,8 @@ const Expression = ({
|
|||
<div
|
||||
className={classnames(
|
||||
'expression',
|
||||
{'wrong-type': realType !== type},
|
||||
{'undefined-type': 'undefined' === realType},
|
||||
{'wrong-type': 'any' !== type && 'undefined' !== type && realType !== type},
|
||||
{'undefined-type': 'any' !== type && 'undefined' === realType},
|
||||
)}
|
||||
>
|
||||
{Renderables}
|
||||
|
@ -306,7 +306,9 @@ const Expression = ({
|
|||
);
|
||||
};
|
||||
|
||||
Expression.defaultProps = {};
|
||||
Expression.defaultProps = {
|
||||
vararg: false,
|
||||
};
|
||||
|
||||
Expression.displayName = 'Expression';
|
||||
|
||||
|
@ -327,6 +329,7 @@ Expression.propTypes = {
|
|||
// eslint-disable-next-line react/forbid-prop-types
|
||||
value: PropTypes.any,
|
||||
}).isRequired,
|
||||
vararg: PropTypes.bool,
|
||||
path: PropTypes.string.isRequired,
|
||||
type: PropTypes.string.isRequired,
|
||||
};
|
||||
|
|
|
@ -58,8 +58,9 @@ const Invocation = ({
|
|||
/>
|
||||
);
|
||||
}
|
||||
const options = description?.args?.[i].options;
|
||||
const type = description?.args?.[i].type || 'undefined';
|
||||
const j = description.vararg ? Math.min(description?.args?.length - 1, i) : i;
|
||||
const options = description?.args?.[j].options;
|
||||
const type = description?.args?.[j].type || 'undefined';
|
||||
return (
|
||||
<Variant
|
||||
context={context}
|
||||
|
@ -68,10 +69,14 @@ const Invocation = ({
|
|||
path={argPath}
|
||||
type={type}
|
||||
value={arg}
|
||||
vararg={
|
||||
'undefined' === type
|
||||
|| (description.vararg && j === description?.args?.length - 1)
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
const isVarArg = 'undefined' === description.type;
|
||||
const isVarArg = 'undefined' === description.type || description.vararg;
|
||||
const args = op.args.concat();
|
||||
if (isVarArg) {
|
||||
args.push({type: 'undefined'});
|
||||
|
@ -108,6 +113,7 @@ Invocation.propTypes = {
|
|||
}),
|
||||
),
|
||||
type: PropTypes.string,
|
||||
vararg: PropTypes.bool,
|
||||
}).isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
op: PropTypes.shape({
|
||||
|
|
Loading…
Reference in New Issue
Block a user