Extracting type mapping into shared module

This commit is contained in:
Jeff Avallone 2019-01-27 08:50:03 -05:00
parent f16a51abcb
commit a118519c3a
3 changed files with 10 additions and 15 deletions

View File

@ -1,16 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import SVG from 'rendering/SVG';
import Text from 'rendering/Text';
import nodeTypes from 'rendering/types';
import style from './style.module.css';
const nodeTypes = {
SVG,
Text
};
const render = (data, extraProps) => {
if (typeof data === 'string') {
return data;
@ -21,7 +15,7 @@ const render = (data, extraProps) => {
(data, key) => render(data, { key }));
return React.createElement(
nodeTypes[type] || type,
nodeTypes[type] ? nodeTypes[type].default : type,
{ ...extraProps, ...props },
children.length === 1 ? children[0] : children);
};

View File

@ -1,13 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import * as SVG from 'rendering/SVG';
import * as Text from 'rendering/Text';
const nodeTypes = {
SVG,
Text
};
import nodeTypes from 'rendering/types';
const layout = data => {
if (typeof data == 'string') {

7
src/rendering/types.js Normal file
View File

@ -0,0 +1,7 @@
import * as SVG from 'rendering/SVG';
import * as Text from 'rendering/Text';
export default {
SVG,
Text
};