Skip to content

Commit 68c1f4d

Browse files
committed
Handle primitive strings as top-level elements in JavaScript
1 parent 5a80783 commit 68c1f4d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

inst/www/react-tools/react-tools.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ window.reactR = (function () {
77
* @param {Object} tag
88
*/
99
function hydrate(components, tag) {
10+
if (typeof tag === 'string') return tag;
1011
if (tag.name[0] === tag.name[0].toUpperCase()
1112
&& !components.hasOwnProperty(tag.name)) {
1213
throw new Error("Unknown component: " + tag.name);
1314
}
1415
var elem = components.hasOwnProperty(tag.name) ? components[tag.name] : tag.name,
1516
args = [elem, tag.attribs];
1617
for (var i = 0; i < tag.children.length; i++) {
17-
if (typeof tag.children[i] === 'object') {
18-
args.push(hydrate(components, tag.children[i]));
19-
} else {
20-
args.push(tag.children[i]);
21-
}
18+
args.push(hydrate(components, tag.children[i]));
2219
}
2320
return React.createElement.apply(React, args);
2421
}
@@ -76,10 +73,13 @@ window.reactR = (function () {
7673
factory: function (el, width, height) {
7774
var lastValue,
7875
renderValue = (function (value) {
79-
// TODO Handle strings naturally
8076
if (actualOptions.renderOnResize) {
81-
value.tag.attribs[actualOptions["widthProperty"]] = formatDimension(width);
82-
value.tag.attribs[actualOptions["heightProperty"]] = formatDimension(height);
77+
// value.tag might be a primitive string, in which
78+
// case there is no attribs property.
79+
if (typeof value.tag === 'object') {
80+
value.tag.attribs[actualOptions["widthProperty"]] = formatDimension(width);
81+
value.tag.attribs[actualOptions["heightProperty"]] = formatDimension(height);
82+
}
8383
lastValue = value;
8484
}
8585
ReactDOM.render(hydrate(components, value.tag), el);

0 commit comments

Comments
 (0)