Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 21b5d04

Browse files
committed
Feat: update generators to use flow types and new best practices
1 parent 148b765 commit 21b5d04

30 files changed

+443
-229
lines changed

app/src/pages/AboutPage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import cssModules from 'react-css-modules';
3-
import { AboutContainer } from 'containers'; // eslint-disable-line
3+
import { AboutContainer } from 'containers';
44
import styles from './index.module.scss';
55

66
const AboutPage = () => (

app/src/pages/LandingPage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import cssModules from 'react-css-modules';
3-
import { LandingContainer } from 'containers'; // eslint-disable-line
3+
import { LandingContainer } from 'containers';
44
import styles from './index.module.scss';
55

66
const LandingPage = () => (

app/src/reducers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import { reducer as formReducer } from 'redux-form';
44
import client from './apolloClient';
55

66
/* GENERATOR: Import all of your reducers */
7+
import test from './containers/Test/reducer';
78
import landing from './containers/LandingContainer/reducer';
89
import app from './containers/AppContainer/reducer';
910

1011
const rootReducer = combineReducers({
1112
app,
1213
/* GENERATOR: Compile all of your reducers */
14+
test,
1315
landing,
1416
routing: routerReducer,
1517
form: formReducer,

app/src/store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import { UserAuthWrapper as userAuthWrapper } from 'redux-auth-wrapper';
66
import rootReducer from './reducers';
77
import client from './apolloClient';
88
/* GENERATOR: Import all of your initial state */
9+
import { initialState as test } from './containers/Test/reducer';
910
import { initialState as landing } from './containers/LandingContainer/reducer';
1011
import { initialState as app } from './containers/AppContainer/reducer';
1112

1213
const initialState = {
1314
/* GENERATOR: Compile all of your initial state */
15+
test,
1416
app,
1517
landing,
1618
};

config/generators/component/es6class.js.hbs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
{{#if wantFlowTypes}}
2+
/* @flow */
3+
{{/if}}
14
{{#if wantPropTypes}}
2-
import React, { PropTypes, Component } from 'react';
5+
import React, { PropTypes } from 'react';
36
{{else}}
4-
import React, { Component } from 'react';
7+
import React from 'react';
8+
{{/if}}
9+
import Box from 'grommet/components/Box';
10+
{{#if imports}}
11+
{{{ createImports imports }}}
512
{{/if}}
613
{{#if wantSCSSModules}}
714
import cssModules from 'react-css-modules';
@@ -11,15 +18,21 @@ import styles from './index.module.scss';
1118
import { StyledWrapper } from './styles';
1219
{{/if}}
1320

14-
class {{ properCase name }} extends Component { // eslint-disable-line react/prefer-stateless-function
21+
{{#if wantFlowTypes}}
22+
type {{ properCase name }}Props = {
23+
24+
}
25+
{{/if}}
26+
27+
class {{ properCase name }} extends React.Component { // eslint-disable-line react/prefer-stateless-function
28+
{{#if wantFlowTypes}}
29+
props: {{ properCase name }}Props;
30+
{{/if}}
1531
render() {
1632
return (
17-
{{#if wantSCSSModules}}
18-
<div className={{curly true}}styles.{{ camelCase name }}{{curly}}>
19-
{{else}}
20-
<div>
21-
{{/if}}
22-
</div>
33+
<Box>
34+
35+
</Box>
2336
);
2437
}
2538
}

config/generators/component/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
{
2727
type: 'confirm',
2828
name: 'wantSCSSModules',
29-
default: true,
29+
default: false,
3030
message: 'Should the component use SCSS Modules?',
3131
},
3232
{
@@ -37,10 +37,32 @@ module.exports = {
3737
},
3838
{
3939
type: 'confirm',
40-
name: 'wantPropTypes',
40+
name: 'wantFlowTypes',
4141
default: true,
42+
message: 'Should the component have FlowTypes?',
43+
},
44+
{
45+
type: 'confirm',
46+
name: 'wantPropTypes',
47+
default: false,
4248
message: 'Should the component have PropTypes?',
4349
},
50+
{
51+
type: 'checkbox',
52+
name: 'imports',
53+
message: 'Would you like to import any commonly used grommet components?',
54+
choices: () => [
55+
{ name: 'Anchor', value: 'Anchor', checked: false },
56+
{ name: 'Article', value: 'Article', checked: false },
57+
{ name: 'Button', value: 'Button', checked: false },
58+
{ name: 'Card', value: 'Card', checked: false },
59+
{ name: 'Heading', value: 'Heading', checked: false },
60+
{ name: 'Header', value: 'Header', checked: false },
61+
{ name: 'Footer', value: 'Footer', checked: false },
62+
{ name: 'Paragraph', value: 'Paragraph', checked: false },
63+
{ name: 'Section', value: 'Section', checked: false },
64+
],
65+
},
4466
],
4567
actions: (data) => {
4668
const actions = [{

config/generators/component/stateless.js.hbs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
{{#if wantFlowTypes}}
2+
/* @flow */
3+
{{/if}}
14
{{#if wantPropTypes}}
25
import React, { PropTypes } from 'react';
36
{{else}}
47
import React from 'react';
58
{{/if}}
9+
import Box from 'grommet/components/Box';
10+
{{#if imports}}
11+
{{{ createImports imports }}}
12+
{{/if}}
613
{{#if wantSCSSModules}}
714
import cssModules from 'react-css-modules';
815
import styles from './index.module.scss';
@@ -11,14 +18,33 @@ import styles from './index.module.scss';
1118
import { StyledWrapper } from './styles';
1219
{{/if}}
1320

14-
const {{ properCase name }} = (props) => (
15-
{{#if wantSCSSModules}}
16-
<div className={{curly true}}styles.{{ camelCase name }}{{curly}}>
17-
{{else}}
18-
<div>
19-
{{/if}}
20-
</div>
21-
);
21+
{{#if wantFlowTypes}}
22+
function {{ properCase name }}(props: {}) {
23+
return (
24+
<Box>
25+
26+
</Box>
27+
);
28+
}
29+
{{else if wantPropTypes}}
30+
{{#unless wantFlowTypes}}
31+
function {{ properCase name }}(props) {
32+
return (
33+
<Box>
34+
35+
</Box>
36+
);
37+
}
38+
{{/unless}}
39+
{{else}}
40+
function {{ properCase name }}() {
41+
return (
42+
<Box>
43+
44+
</Box>
45+
);
46+
}
47+
{{/if}}
2248

2349
{{#if wantPropTypes}}
2450
{{ properCase name }}.propTypes = {

config/generators/component/test.js.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { shallow } from 'enzyme';
22
import { shallowToJson } from 'enzyme-to-json';
33
import React from 'react';
4-
import { spy } from 'sinon';
4+
// import { spy } from 'sinon';
55
import {{ properCase name }} from '../index';
66

77
describe('<{{ properCase name }} />', () => {
88
it('should render with default props', () => {
99
const wrapper = shallow(
10-
<{{ properCase name }} />
10+
<{{ properCase name }} />,
1111
);
1212
expect(shallowToJson(wrapper)).toMatchSnapshot();
1313
});

config/generators/container/README.md.hbs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
import * as types from './constants';
1+
{{#if wantFlowTypes}}
2+
/* @flow */
3+
{{/if}}
4+
import * as T from './constants';
5+
{{#if wantFlowTypes}}
6+
import type { {{ properCase name }}Action } from './flowTypes';
27

3-
// {{ camelCase name }}defaultAction :: None -> {Action}
4-
export const {{ camelCase name }}DefaultAction = () => ({
5-
type: types.{{ uppercase name }}_DEFAULT_ACTION,
8+
export const loadDataInitiation = (): {{ properCase name }}Action => ({
9+
type: T.LOAD_DATA_INITIATION,
610
});
11+
12+
export const loadDataSuccess = (): {{ properCase name }}Action => ({
13+
type: T.LOAD_DATA_SUCCESS,
14+
});
15+
16+
export const loadDataFailure = (error: { message: string }): {{ properCase name }}Action => ({
17+
type: T.LOAD_DATA_FAILURE,
18+
error,
19+
});
20+
{{else}}
21+
22+
export const loadDataInitiation = () => ({
23+
type: T.LOAD_DATA_INITIATION,
24+
});
25+
26+
export const loadDataSuccess = () => ({
27+
type: T.LOAD_DATA_SUCCESS,
28+
});
29+
30+
export const loadDataFailure = (error) => ({
31+
type: T.LOAD_DATA_FAILURE,
32+
error,
33+
});
34+
{{/if}}

0 commit comments

Comments
 (0)