2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-11 18:02:26 +03:00

feat(*): react render support, move some helper functions to plugin-helper

This commit is contained in:
Nikolay Kostyurin
2018-08-09 02:45:19 +02:00
parent 846d93a2a4
commit 1a84968ea2
20 changed files with 471 additions and 169 deletions
+35
View File
@@ -0,0 +1,35 @@
const React = require('react');
const { isTagNode, isStringNode } = require('@bbob/plugin-helper');
function tagToReactElement(node) {
if (node.content === null) {
return React.createElement(
node.tag,
node.attrs,
null,
);
}
return React.createElement(
node.tag,
node.attrs,
// eslint-disable-next-line no-use-before-define
render(node.content),
);
}
function render(nodes) {
const els = nodes.reduce((arr, node) => {
if (isTagNode(node)) {
arr.push(tagToReactElement(node));
} else if (isStringNode(node)) {
arr.push(node);
}
return arr;
}, []);
return els;
}
module.exports = render;