Remove switch statement if there are no props

Summary: Don't generate the switch statement if there are no props

Reviewed By: JoshuaGross

Differential Revision: D16417803

fbshipit-source-id: 87eda785c836f5e406e27d3c2990ec7f69422bdb
This commit is contained in:
Rick Hanlon
2019-07-24 10:36:23 -07:00
committed by Facebook Github Bot
parent d143edc298
commit 58d3cb2fff
2 changed files with 10 additions and 14 deletions
@@ -27,9 +27,7 @@ package com.facebook.react.viewmanagers;
public class ::_CLASSNAME_::<T extends ::_EXTEND_CLASSES_::> {
public void setProperty(::_INTERFACE_CLASSNAME_::<T> viewManager, T view, String propName, Object value) {
switch (propName) {
::_PROP_CASES_::
}
::_PROP_CASES_::
}
}
`;
@@ -77,10 +75,10 @@ function generatePropCasesString(
componentName: string,
) {
if (component.props.length === 0) {
return ' // No props';
return '// No props';
}
return component.props
const cases = component.props
.map(prop => {
return `case "${prop.name}":
viewManager.set${toSafeJavaString(
@@ -89,6 +87,10 @@ function generatePropCasesString(
break;`;
})
.join('\n' + ' ');
return `switch (propName) {
${cases}
}`;
}
function getClassExtendString(component): string {