Skip to content

Commit 8750e93

Browse files
authored
Merge pull request #70 from CVarisco/68-Extraneous-null-emitted-generateMethods
Fix generateComponentMethods that print null when is empty
2 parents c6725ef + e35fe86 commit 8750e93

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/defaultTemplates/js/common.template.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,26 @@ const COMPONENT_TYPES = {
66
}
77

88
function generateReactImport(componentType) {
9-
return `import React${componentType !== 'stateless' ? `, { ${COMPONENT_TYPES[componentType]} }` : ''} from 'react'`
9+
return `import React${
10+
componentType !== 'stateless' ? `, { ${COMPONENT_TYPES[componentType]} }` : ''
11+
} from 'react'`
1012
}
1113

14+
/**
15+
* Create the concatenation of methods string that will be injected into class and pure components
16+
* @param {Array} componentMethods
17+
* @return {String} methods
18+
*/
1219
function generateComponentMethods(componentMethods) {
1320
if (componentMethods.length === 0) {
14-
return null
21+
return ''
1522
}
16-
let methods = ''
17-
componentMethods.forEach((method) => {
18-
methods += `\n\xa0\xa0\xa0\xa0${method}(){}\n`
19-
})
20-
return methods
23+
24+
return componentMethods.reduce((acc, method) => {
25+
const methods = `${acc}\n\xa0\xa0\xa0\xa0${method}(){}\n`
26+
27+
return methods
28+
}, '')
2129
}
2230

2331
function generateImports(

0 commit comments

Comments
 (0)