diff --git a/src/client/components/persea.jsx b/src/client/app.jsx similarity index 59% rename from src/client/components/persea.jsx rename to src/client/app.jsx index 4a1d6d8..6c530b7 100644 --- a/src/client/components/persea.jsx +++ b/src/client/app.jsx @@ -1,23 +1,24 @@ +import './app.scss'; + import {hot} from 'react-hot-loader'; import React, {useState} from 'react'; -import TypeRenderersContext from '~/client/context/typeRenderers'; -import {all as allTypeRenderers} from '~/client/type-renderers.scwp'; - -import Entity from './entity'; +import TypeRenderersContext from './context/typeRenderers'; +import Resource from './resource'; +import {all as allTypeRenderers} from './type-renderers.scwp'; const typeRenderMap = () => Object.values(allTypeRenderers()).reduce((r, M) => { const {default: {type, Component}} = M; return {...r, [type]: Component}; }, {}); -const Persea = () => { +const App = () => { const [typeRenderers] = useState(typeRenderMap()); return ( - + ); }; -export default hot(module)(Persea); +export default hot(module)(App); diff --git a/src/client/app.scss b/src/client/app.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/client/index.jsx b/src/client/index.jsx index 0465dc1..dd1fec4 100644 --- a/src/client/index.jsx +++ b/src/client/index.jsx @@ -4,13 +4,8 @@ import {enableMapSet} from 'immer'; import React from 'react'; import {render} from 'react-dom'; -import Persea from '~/client/components/persea'; +import App from './app'; enableMapSet(); -render( - ( - - ), - document.getElementById('root'), -); +render(, document.getElementById('root')); diff --git a/src/client/resource.jsx b/src/client/resource.jsx new file mode 100644 index 0000000..6a11f9b --- /dev/null +++ b/src/client/resource.jsx @@ -0,0 +1,20 @@ +import './app.scss'; + +import React from 'react'; + +import {all} from './resources.scwp'; + +const resources = Object.values(all()).map((M) => M.default); + +const Resource = (props) => { + const { + uri, + } = props; + const resource = resources.find((resource) => uri.match(resource.matcher)); + const {Component} = resource + ? resource + : {Component: () =>
No loader for `{uri}`.
}; + return
; +}; + +export default Resource; diff --git a/src/client/resources.scwp.js b/src/client/resources.scwp.js new file mode 100644 index 0000000..ae0eae1 --- /dev/null +++ b/src/client/resources.scwp.js @@ -0,0 +1,3 @@ +module.exports = function types(scwp) { + scwp.autoreg('resource'); +}; diff --git a/src/client/components/entity.jsx b/src/client/resources/entity/component/index.jsx similarity index 85% rename from src/client/components/entity.jsx rename to src/client/resources/entity/component/index.jsx index d825b35..317b562 100644 --- a/src/client/components/entity.jsx +++ b/src/client/resources/entity/component/index.jsx @@ -6,12 +6,13 @@ import React from 'react'; import Traits from './traits'; const decorate = compose( - contempo(require('./entity.raw.scss')), + contempo(require('./index.raw.scss')), ); const json = require('~/../fixtures/rock-projectile.entity.json'); -const EntityComponent = () => { +const EntityComponent = (props) => { + const {uri} = props; const entity = new Entity(json); const {traits} = json; return ( diff --git a/src/client/components/entity.raw.scss b/src/client/resources/entity/component/index.raw.scss similarity index 100% rename from src/client/components/entity.raw.scss rename to src/client/resources/entity/component/index.raw.scss diff --git a/src/client/components/traits.jsx b/src/client/resources/entity/component/traits.jsx similarity index 98% rename from src/client/components/traits.jsx rename to src/client/resources/entity/component/traits.jsx index 57d452f..7d54814 100644 --- a/src/client/components/traits.jsx +++ b/src/client/resources/entity/component/traits.jsx @@ -15,7 +15,7 @@ import { import {createSelector} from '@reduxjs/toolkit'; import {deregisterHooks, registerHooks} from 'scwp'; -import Value from './types/value.type-renderer'; +import Value from '~/client/components/types/value.type-renderer'; const SCROLL_MAG = 80; diff --git a/src/client/components/traits.raw.scss b/src/client/resources/entity/component/traits.raw.scss similarity index 100% rename from src/client/components/traits.raw.scss rename to src/client/resources/entity/component/traits.raw.scss diff --git a/src/client/resources/entity/entity.resource.js b/src/client/resources/entity/entity.resource.js new file mode 100644 index 0000000..fbabc52 --- /dev/null +++ b/src/client/resources/entity/entity.resource.js @@ -0,0 +1,6 @@ +import EntityComponent from './component'; + +export default { + matcher: /\.entity\.json$/, + Component: EntityComponent, +}; diff --git a/src/client/resources/entity/slice.js b/src/client/resources/entity/slice.js new file mode 100644 index 0000000..e69de29