Skip to content

Commit

Permalink
Simplify Svg element render method and pickNotNil
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Jan 25, 2019
1 parent 73e85b6 commit f5cdc31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 6 additions & 3 deletions elements/Svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export default class Svg extends Shape {
flex: 0,
} : null;

const o = +opacity;
const opacityStyle = !isNaN(o) ? {
opacity: o,
} : null;

return (
<NativeSvgView
{...props}
Expand All @@ -108,9 +113,7 @@ export default class Svg extends Shape {
style={[
styles.svg,
style,
!isNaN(+opacity) && {
opacity: +opacity,
},
opacityStyle,
dimensions,
]}
{...extractResponder(props, this)}
Expand Down
14 changes: 6 additions & 8 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
export function pickNotNil(object) {
const result = {};
const keys = Object.keys(object);
const l = keys.length;
for (let i = 0; i < l; i++) {
const key = keys[i];
const value = object[key];
// eslint-disable-next-line eqeqeq
if (value != null) {
result[key] = value;
for (const key in object) {
if (object.hasOwnProperty(key)) {
const value = object[key];
if (value !== undefined && value !== null) {
result[key] = value;
}
}
}
return result;
Expand Down

0 comments on commit f5cdc31

Please sign in to comment.