diff --git a/src/client/components/persea.jsx b/src/client/components/persea.jsx index f260613..4a1d6d8 100644 --- a/src/client/components/persea.jsx +++ b/src/client/components/persea.jsx @@ -1,10 +1,23 @@ import {hot} from 'react-hot-loader'; -import React from 'react'; +import React, {useState} from 'react'; + +import TypeRenderersContext from '~/client/context/typeRenderers'; +import {all as allTypeRenderers} from '~/client/type-renderers.scwp'; import Entity from './entity'; -const Persea = () => ( - -); +const typeRenderMap = () => Object.values(allTypeRenderers()).reduce((r, M) => { + const {default: {type, Component}} = M; + return {...r, [type]: Component}; +}, {}); + +const Persea = () => { + const [typeRenderers] = useState(typeRenderMap()); + return ( + + + + ); +}; export default hot(module)(Persea); diff --git a/src/client/components/traits.jsx b/src/client/components/traits.jsx index d908dd4..57d452f 100644 --- a/src/client/components/traits.jsx +++ b/src/client/components/traits.jsx @@ -15,7 +15,7 @@ import { import {createSelector} from '@reduxjs/toolkit'; import {deregisterHooks, registerHooks} from 'scwp'; -import {all as allTypeRenderers} from './types/type-renderers.scwp'; +import Value from './types/value.type-renderer'; const SCROLL_MAG = 80; @@ -43,20 +43,10 @@ const ensureTraitComponents = () => { }, {}); } }; -let TypeRenderers; -const ensureTypeRenderers = () => { - if (!TypeRenderers) { - TypeRenderers = Object.values(allTypeRenderers()).reduce((r, M) => { - const {default: {type, Component}} = M; - return {...r, [type]: Component}; - }, {}); - } -}; const makeTabSelector = (context, type) => createSelector( (_) => _, (trait) => { - ensureTypeRenderers(); ensureTraitComponents(); const {params: paramsRaw, state: stateRaw} = trait; const {[type]: TraitComponent} = TraitComponents; @@ -68,27 +58,19 @@ const makeTabSelector = (context, type) => createSelector( const renderComponents = (description, values) => ( // eslint-disable-next-line no-shadow Object.values(mapObject(description, (description, key) => { - const {label, options, type: componentType} = description; - const Component = TypeRenderers[componentType]; + const {label, options} = description; return ( -