Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #142 from FormidableLabs/bug-onlyChildIsString
Browse files Browse the repository at this point in the history
Bug: Make Children.only check handle string children
  • Loading branch information
alexlande committed May 13, 2015
2 parents 0091886 + dc6ceff commit a8a0d23
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ rules:
no-spaced-func: 2 # disallow space between function identifier and application
no-ternary: 0 # disallow the use of ternary operators

no-trailing-spaces: 2 # disallow trailing whitespace at the end of lines
no-trailing-spaces: 1 # disallow trailing whitespace at the end of lines
no-multiple-empty-lines: 2 # disallow multiple empty lines
no-underscore-dangle: 0 # disallow dangling underscores in identifiers
no-wrap-func: 2 # disallow wrapping of non-IIFE statements in parens
Expand Down
7 changes: 7 additions & 0 deletions modules/__tests__/resolve-styles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,13 @@ describe('resolveStyles', function () {

expect(React.Children.only(result.props.children)).toBeTruthy();
});

it.only('doesn\'t break when only child isn\'t ReactElement', function () {

This comment has been minimized.

Copy link
@ianobermiller

ianobermiller May 13, 2015

Contributor

remove .only

var component = genComponent();
var renderedElement = <div>Foo</div>;

resolveStyles(component, renderedElement);
});
});

});
6 changes: 3 additions & 3 deletions modules/keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var createMarkupForStyles = function (style) {

// Simple animation helper that injects CSS into a style object containing the
// keyframes, and returns a string with the generated animation name.
var keyframes = function (keyframes) {
var keyframes = function (keyframeRules) {
var name = 'Animation' + animationIndex;
animationIndex += 1;

Expand All @@ -39,8 +39,8 @@ var keyframes = function (keyframes) {
}

var rule = '@' + keyframesPrefixed + ' ' + name + ' {\n' +
Object.keys(keyframes).map(function (percentage) {
var props = keyframes[percentage];
Object.keys(keyframeRules).map(function (percentage) {
var props = keyframeRules[percentage];
var prefixedProps = prefix(props, 'css');
var serializedProps = createMarkupForStyles(prefixedProps);
return ' ' + percentage + ' {\n ' + serializedProps + '\n }';
Expand Down
10 changes: 7 additions & 3 deletions modules/resolve-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,20 @@ var resolveStyles = function (component, renderedElement, existingKeyMap) {
var newChildren = null;
var oldChildren = renderedElement.props.children;
if (oldChildren) {
if (React.Children.count(oldChildren) === 1) {
var child = React.Children.only(oldChildren);
newChildren = resolveStyles(component, child, existingKeyMap);
// If a React Element is an only child, don't wrap it in an array for
// React.Children.map() for React.Children.only() compatibility.
if (React.Children.count(oldChildren) === 1 && oldChildren.type) {
var onlyChild = React.Children.only(oldChildren);

This comment has been minimized.

Copy link
@ianobermiller

ianobermiller May 13, 2015

Contributor

So React.Children.only doesn't like string children? That seems wrong :/


This comment has been minimized.

Copy link
@ianobermiller

ianobermiller May 13, 2015

Contributor

extra newline?

newChildren = resolveStyles(component, onlyChild, existingKeyMap);
} else {
newChildren = React.Children.map(
oldChildren,
function (child) {
if (React.isValidElement(child)) {
return resolveStyles(component, child, existingKeyMap);
}

return child;
}
);
Expand Down

0 comments on commit a8a0d23

Please sign in to comment.