fix: early-out for literal

This commit is contained in:
cha0s 2020-06-23 20:17:55 -05:00
parent 4a7afab0df
commit 92acaa3b86

View File

@ -1,4 +1,4 @@
import {makeCompilable} from '@avocado/behavior'; import {makeCompilable, description as typeDescription} from '@avocado/behavior';
import {compose} from '@avocado/core'; import {compose} from '@avocado/core';
import contempo from 'contempo'; import contempo from 'contempo';
import React from 'react'; import React from 'react';
@ -16,7 +16,7 @@ const decorate = compose(
contempo(require('./expression.raw.scss')), contempo(require('./expression.raw.scss')),
); );
const Traversal = (props) => { const Expression = (props) => {
const { const {
context, context,
onChange = () => {}, onChange = () => {},
@ -39,6 +39,11 @@ const Traversal = (props) => {
<span className="key" data-op-key={op.key}> <span className="key" data-op-key={op.key}>
<select <select
onChange={(event) => { onChange={(event) => {
if ('<literal>' === event.target.value) {
const {defaultLiteral} = typeDescription(type, undefined);
onChange({type: 'literal', value: defaultLiteral}, event);
return;
}
const newSteps = [ const newSteps = [
...ops.slice(0, i), ...ops.slice(0, i),
{ {
@ -46,7 +51,7 @@ const Traversal = (props) => {
key: event.target.value, key: event.target.value,
}, },
]; ];
return onChange({ onChange({
...value, ...value,
ops: defaultOps(context, type, newSteps), ops: defaultOps(context, type, newSteps),
value: undefined, value: undefined,
@ -55,7 +60,7 @@ const Traversal = (props) => {
value={op.key} value={op.key}
> >
{ {
options [...options, '<literal>']
.sort((l, r) => (l.toLowerCase() < r.toLowerCase() ? -1 : 1)) .sort((l, r) => (l.toLowerCase() < r.toLowerCase() ? -1 : 1))
.map((option) => <option key={option}>{option}</option>) .map((option) => <option key={option}>{option}</option>)
} }
@ -133,11 +138,11 @@ const Traversal = (props) => {
); );
}; };
Traversal.propTypes = { Expression.propTypes = {
...propTypes, ...propTypes,
}; };
export default { export default {
type: 'expression', type: 'expression',
Component: decorate(Traversal), Component: decorate(Expression),
}; };