feat: resource
This commit is contained in:
parent
82470b9747
commit
063be814ca
|
@ -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 (
|
||||
<TypeRenderersContext.Provider value={typeRenderers}>
|
||||
<Entity />
|
||||
<Resource uri="/mama-kitty.entity.json" />
|
||||
</TypeRenderersContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default hot(module)(Persea);
|
||||
export default hot(module)(App);
|
0
src/client/app.scss
Normal file
0
src/client/app.scss
Normal file
|
@ -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(
|
||||
(
|
||||
<Persea />
|
||||
),
|
||||
document.getElementById('root'),
|
||||
);
|
||||
render(<App />, document.getElementById('root'));
|
||||
|
|
20
src/client/resource.jsx
Normal file
20
src/client/resource.jsx
Normal file
|
@ -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: () => <div className="unloadable">No loader for `<code>{uri}</code>`.</div>};
|
||||
return <div className="resource"><Component uri={uri} /></div>;
|
||||
};
|
||||
|
||||
export default Resource;
|
3
src/client/resources.scwp.js
Normal file
3
src/client/resources.scwp.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = function types(scwp) {
|
||||
scwp.autoreg('resource');
|
||||
};
|
|
@ -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 (
|
|
@ -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;
|
||||
|
6
src/client/resources/entity/entity.resource.js
Normal file
6
src/client/resources/entity/entity.resource.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import EntityComponent from './component';
|
||||
|
||||
export default {
|
||||
matcher: /\.entity\.json$/,
|
||||
Component: EntityComponent,
|
||||
};
|
0
src/client/resources/entity/slice.js
Normal file
0
src/client/resources/entity/slice.js
Normal file
Loading…
Reference in New Issue
Block a user