chore: tidy

This commit is contained in:
cha0s 2020-06-21 22:52:41 -05:00
parent 0c7974b885
commit 53c626b689

View File

@ -19,11 +19,11 @@ const ensureTraitComponents = () => {
} }
}; };
const makePane = (context, dispatch, target, type) => (trait) => { const makeTraitPaneRenderer = (context, dispatch, target, traitType) => (trait) => {
ensureTraitComponents(); ensureTraitComponents();
const {params, state} = trait; const {params, state} = trait;
const {[type]: TraitComponent} = TraitComponents; const {[traitType]: TraitComponent} = TraitComponents;
const Trait = lookupTrait(type); const Trait = lookupTrait(traitType);
if (!Trait) { if (!Trait) {
return null; return null;
} }
@ -34,6 +34,12 @@ const makePane = (context, dispatch, target, type) => (trait) => {
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
Object.values(mapObject(description, (description, key) => { Object.values(mapObject(description, (description, key) => {
const {label, options} = description; const {label, options} = description;
const payload = {
target,
trait: traitType,
half,
key,
};
return ( return (
<label key={key}> <label key={key}>
<span className="text"> <span className="text">
@ -44,20 +50,8 @@ const makePane = (context, dispatch, target, type) => (trait) => {
<Value.Component <Value.Component
context={context} context={context}
dispatchers={{ dispatchers={{
onChange: (value) => dispatch(setTraitProperty({ onChange: (value) => dispatch(setTraitProperty({...payload, value})),
target, onIncrement: (value) => dispatch(incrementTraitProperty({...payload, value})),
trait: type,
half,
key,
value,
})),
onIncrement: (value) => dispatch(incrementTraitProperty({
target,
trait: type,
half,
key,
value,
})),
}} }}
options={options} options={options}
value={values[key]} value={values[key]}
@ -84,7 +78,7 @@ const TraitPane = (props) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
// TODO: dependency on context is too noisy // TODO: dependency on context is too noisy
const renderTraitPane = useMemo( const renderTraitPane = useMemo(
() => makePane(context, dispatch, target, type), () => makeTraitPaneRenderer(context, dispatch, target, type),
[context, dispatch, target, type], [context, dispatch, target, type],
); );
return useMemo( return useMemo(