Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(Flex): handle cases of falsy values provided as children #890

Merged
merged 9 commits into from
Feb 12, 2019

Conversation

kuzhelov
Copy link
Contributor

No description provided.

let isFirstElement = true
return React.Children.map(children, (child: any) => {
const maybeChildElement =
child && child.type && ((child.type as any) as typeof FlexItem).__isFlexItem
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed failures when child is null - happens when primitive values (other than string) are passed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const isFlexItem = child && child.type && ((child.type as any) as typeof FlexItem).__isFlexItem
// or 
const isFlexItem: boolean = _.get(child, 'type.__isFlexItem')

@codecov
Copy link

codecov bot commented Feb 12, 2019

Codecov Report

Merging #890 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #890   +/-   ##
=======================================
  Coverage   92.99%   92.99%           
=======================================
  Files          21       21           
  Lines         728      728           
  Branches       69       69           
=======================================
  Hits          677      677           
  Misses         51       51

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 272d18e...5d0cd5c. Read the comment docs.

{renderGap && gap && <Flex.Gap className={cx(`${Flex.className}__gap`, gapClasses)} />}
{childElement}
</>
maybeChildElement && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a condition there?
Without it we will get:

<>
  {null}
  {null}
</>

But it will not affect the markup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind,

If children is null or undefined, this method will return null or undefined rather than an array.
https://reactjs.org/docs/react-api.html#reactchildrenmap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - but, essentially, we won't like to draw anything if falsy value is provided - and this is exactly the effect logic provides. Thus I would rather leave it the way it is now - as a benefit this won't introduce any additional React elements to output elements tree

@kuzhelov kuzhelov changed the title fix(Flex): fix gap logic and handle corner null cases and fix(Flex): handle cases of falsy values provided as children Feb 12, 2019
@@ -78,7 +78,7 @@ class FlexItem extends UIComponent<Extendable<FlexItemProps>> {
})
}

return applyStyles(React.Children.only(children), styles, classes)
return children ? applyStyles(React.Children.only(children), styles, classes) : children
Copy link
Member

@layershifter layershifter Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return children ? applyStyles(React.Children.only(children), styles, classes) : children
return _.isNil(children) ? null : applyStyles(React.Children.only(children), styles, classes)

May be this will be more clear?

@kuzhelov kuzhelov merged commit d4c7292 into master Feb 12, 2019
@kuzhelov kuzhelov deleted the fix/flex branch February 12, 2019 19:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants