chore: tidy

This commit is contained in:
cha0s 2020-06-26 05:59:15 -05:00
parent 69ec9ef50f
commit 5b06b3a139
3 changed files with 18 additions and 21 deletions

View File

@ -25,12 +25,11 @@ const EntityComponent = (props) => {
return null;
}
const entity = new Entity(json);
const {traits} = json;
return (
<div className="entity">
<div className="document-pane" />
<div className="settings-pane">
<Traits context={entity.context} entity={entity} target={json.uuid} traits={traits} />
<Traits entity={entity} traits={json.traits} />
</div>
</div>
);

View File

@ -11,18 +11,14 @@ import Value from '~/client/value';
import {setTraitProperty} from './state';
const traitComponents = memoize(() => {
return Object.values(allTraitComponents()).reduce((r, M) => {
const traitComponents = memoize(() => Object.values(allTraitComponents()).reduce((r, M) => {
const {default: TraitComponent} = M;
return {...r, [TraitComponent.type]: TraitComponent};
}, {});
});
}, {}));
const TraitPane = (props) => {
const {
context,
entity,
target,
trait,
type: traitType,
} = props;
@ -41,7 +37,7 @@ const TraitPane = (props) => {
Object.values(mapObject(description, (description, key) => {
const {label, options, type} = description;
const payload = {
target,
target: entity.uuid,
trait: traitType,
half,
key,
@ -54,7 +50,7 @@ const TraitPane = (props) => {
</span>
<div className="invisible-separator" />
<Value.Component
context={context}
context={entity.context}
onChange={(value) => dispatch(setTraitProperty({...payload, value}))}
options={'function' === typeof options ? options(entity) : options}
type={type}
@ -73,9 +69,14 @@ const TraitPane = (props) => {
};
TraitPane.propTypes = {
context: PropTypes.shape({}).isRequired,
target: PropTypes.string.isRequired,
trait: PropTypes.shape({}).isRequired,
entity: PropTypes.shape({
context: PropTypes.shape({}),
uuid: PropTypes.string,
}).isRequired,
trait: PropTypes.shape({
params: PropTypes.shape({}),
state: PropTypes.shape({}),
}).isRequired,
type: PropTypes.string.isRequired,
};
@ -83,7 +84,7 @@ export default TraitPane;
if (module.hot) {
registerHooks({
autoreg$accept: (type, M) => {
autoreg$accept: (type) => {
if ('trait-component' === type) {
traitComponents.cache.clear();
}

View File

@ -30,7 +30,7 @@ const decorate = compose(
// );
const Traits = (props) => {
const {context, entity, target, traits} = props;
const {entity, traits} = props;
const [tabIndex, setTabIndex] = useState(0);
let listRef;
const entries = Object.entries(traits);
@ -61,10 +61,8 @@ const Traits = (props) => {
{entries.map(([type, trait]) => (
<TabPanel key={type}>
<TraitPane
context={context}
entity={entity}
key={type}
target={target}
trait={trait}
type={type}
/>
@ -76,8 +74,7 @@ const Traits = (props) => {
};
Traits.propTypes = {
context: PropTypes.shape({}).isRequired,
target: PropTypes.string.isRequired,
entity: PropTypes.shape({}).isRequired,
traits: PropTypes.shape({}).isRequired,
};