chore: tidy

This commit is contained in:
cha0s 2020-06-21 22:43:52 -05:00
parent b1b524bb60
commit bc1ca174b0

View File

@ -21,16 +21,15 @@ const ensureTraitComponents = () => {
const makePane = (context, dispatch, target, type) => (trait) => {
ensureTraitComponents();
const {params: paramsRaw, state: stateRaw} = trait;
const {params, state} = trait;
const {[type]: TraitComponent} = TraitComponents;
const Trait = lookupTrait(type);
const params = Trait ? {...Trait.defaultParams(), ...paramsRaw} : paramsRaw;
const state = Trait ? {...Trait.defaultState(), ...stateRaw} : stateRaw;
if (!Trait) {
return null;
}
if (TraitComponent) {
return <TraitComponent params={params} state={state} />;
}
const paramsDescription = Trait?.describeParams() || {};
const stateDescription = Trait?.describeState() || {};
const renderComponents = (traitHalf, description, values) => (
// eslint-disable-next-line no-shadow
Object.values(mapObject(description, (description, key) => {
@ -69,8 +68,8 @@ const makePane = (context, dispatch, target, type) => (trait) => {
);
return (
<form className="trait-component-builtin">
{renderComponents('params', paramsDescription, params)}
{renderComponents('state', stateDescription, state)}
{renderComponents('params', Trait.describeParams(), params)}
{renderComponents('state', Trait.describeState(), state)}
</form>
);
};