Skip to content

Commit d0660f0

Browse files
committed
some change
1 parent 998d777 commit d0660f0

File tree

30 files changed

+147
-764
lines changed

30 files changed

+147
-764
lines changed

.flowconfig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ module.name_mapper='\$components' -> '<PROJECT_ROOT>/src/components'
1111
module.name_mapper='\$styles' -> '<PROJECT_ROOT>/src/styles'
1212
module.name_mapper='\$containers' -> '<PROJECT_ROOT>/src/containers'
1313
module.name_mapper='\$reducers' -> '<PROJECT_ROOT>/src/reducers'
14-
module.name_mapper='\$layouts' -> '<PROJECT_ROOT>/src/layouts'
14+
module.name_mapper='\$layouts' -> '<PROJECT_ROOT>/src/layouts'
15+
module.file_ext=.css
16+
module.file_ext=.less

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#react-redux-boilerplate
22

3-
react+redux+react-router3(async) and so on...
3+
react+redux+react-router4.x+flow
44

55
about test, I will write. please wait a moment!
66

@@ -12,9 +12,7 @@ $ yarn install(or npm install)
1212
$ npm start
1313
```
1414
## Related issue
15-
1. [react-hot-loader do not support with async router](https://github.com/gaearon/react-hot-boilerplate/pull/61#issuecomment-218835358)
16-
2. [router3 will console a warning with react-hot-loader](https://github.com/gaearon/react-hot-loader/issues/249)
17-
15+
1816
## License
1917

2018
MIT

bin/www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @flow
1+
//
22
const debug = require('debug')('app:bin:www');
33
const ip = require('internal-ip');
44
const detect = require('detect-port');

build/webpack-config/loaders.js

Lines changed: 75 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,85 @@ const ExtractTextPlugin = require('extract-text-webpack-plugin');
55
const isDev = env.__DEV__;
66
const isProd = env.__PRO__;
77
module.exports = () => {
8-
const rules = [{
9-
test: /\.(js|jsx)$/,
10-
exclude: /node_modules/,
11-
use: [{ loader: 'babel-loader' }]
12-
}, {
13-
test: /\.json$/,
14-
use: [{ loader: 'json-loader' }]
15-
}, {
16-
test: /\.css$/,
17-
use: [{
18-
loader: 'style-loader'
19-
}, {
20-
loader: 'css-loader',
21-
options: {
22-
minimize: isProd
23-
}
24-
}, {
25-
loader: 'postcss-loader'
26-
}]
27-
}, {
28-
test: /\.less$/,
29-
use: [{
30-
loader: 'style-loader'
31-
}, {
32-
loader: 'css-loader',
33-
options: {
34-
minimize: isProd
35-
}
36-
}, {
37-
loader: 'postcss-loader'
38-
}, {
39-
loader: 'less-loader',
40-
options: {
41-
sourceMap: !isProd
42-
}
43-
}]
44-
}, {
45-
test: /\.(png|jpg)$/,
46-
use: [{
47-
loader: 'url-loader',
48-
options: {
49-
limit: 8192
50-
}
51-
}]
52-
}];
8+
const rules = [
9+
{
10+
test: /\.(js|jsx)$/,
11+
exclude: /node_modules/,
12+
use: [{ loader: 'babel-loader' }],
13+
},
14+
{
15+
test: /\.json$/,
16+
use: [{ loader: 'json-loader' }],
17+
},
18+
{
19+
test: /\.css$/,
20+
use: [
21+
{
22+
loader: 'style-loader',
23+
},
24+
{
25+
loader: 'css-loader',
26+
options: {
27+
minimize: isProd,
28+
module: true,
29+
},
30+
},
31+
{
32+
loader: 'postcss-loader',
33+
},
34+
],
35+
},
36+
{
37+
test: /\.less$/,
38+
use: [
39+
{
40+
loader: 'style-loader',
41+
},
42+
{
43+
loader: 'css-loader',
44+
options: {
45+
minimize: isProd,
46+
module: true,
47+
},
48+
},
49+
{
50+
loader: 'postcss-loader',
51+
},
52+
{
53+
loader: 'less-loader',
54+
options: {
55+
sourceMap: !isProd,
56+
},
57+
},
58+
],
59+
},
60+
{
61+
test: /\.(png|jpg)$/,
62+
use: [
63+
{
64+
loader: 'url-loader',
65+
options: {
66+
limit: 8192,
67+
},
68+
},
69+
],
70+
},
71+
];
5372
if (!isDev) {
5473
debug('Apply ExtractTextPlugin to CSS loaders.');
55-
rules.filter(rule => rule.use && rule.use.find(loaderObj => /css/.test(loaderObj.loader.split('?')[0])))
56-
.forEach((rule) => {
74+
rules
75+
.filter(
76+
rule =>
77+
rule.use &&
78+
rule.use.find(loaderObj => /css/.test(loaderObj.loader.split('?')[0]))
79+
)
80+
.forEach(rule => {
5781
const first = rule.use[0];
5882
const rest = rule.use.slice(1);
59-
rule.loader = ExtractTextPlugin.extract({ fallback: first, loader: rest });
83+
rule.loader = ExtractTextPlugin.extract({
84+
fallback: first,
85+
loader: rest,
86+
});
6087
delete rule.use;
6188
});
6289
}

flow-typed/self-define/injectAbleStore.js renamed to flow-typed/sefl-define.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @flow
2+
declare var __DEV__: boolean;
23
declare module '$self-define' {
34
declare type StoreWithInjectAble = {
45
inject: (namespace: any, reducer: any) => void,
@@ -13,7 +14,7 @@ declare module '$self-define' {
1314
};
1415
declare type RouteProps = {
1516
path: string,
16-
component: (props?: Object) => React$Element<any>,
17+
component: ?React$Component<any, any, any> | ((props?: Object) => React$Element<any>),
1718
routes?: Array<Object>,
1819
exact?: boolean
1920
};

flow-typed/self-define/react.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"start": "better-npm-run start",
88
"compile": "better-npm-run compile",
99
"lint": "eslint src",
10-
"flow": "flow",
10+
"flowCheck": "flow",
1111
"lint:fix": "npm run lint -- --fix",
1212
"start:dist": "better-npm-run start:dist"
1313
},
@@ -97,7 +97,7 @@
9797
"whatwg-fetch": "^2.0.3"
9898
},
9999
"pre-commit": [
100-
"flow",
100+
"flowCheck",
101101
"lint"
102102
]
103103
}

src/Test.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/app.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/components/Header/Header.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import React from 'react';
2-
import { Link } from 'react-router-dom';
3-
import './Header.less';
2+
import { NavLink } from 'react-router-dom';
3+
import HeaderModule from './Header.less';
44

55
export const Header = () => (
66
<div>
77
<h1>Magic-FE React Redux Boilerplate</h1>
8-
<Link to="/">
8+
<NavLink exact to="/" activeClassName={HeaderModule['route--active']}>
99
Home
10-
</Link>
10+
</NavLink >
1111
{' · '}
12-
<Link to="/increase">
12+
<NavLink to="/increase" activeClassName={HeaderModule['route--active']}>
1313
Increase
14-
</Link>
15-
{' · '}
16-
<Link to="/increase2">
17-
Increase2
18-
</Link>
14+
</NavLink >
1915
</div>
2016
);
2117

src/components/RouteWithSubRoutes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @flow
1+
//
22
import React from 'react';
33
import { Route } from 'react-router-dom';
44
import type { RouteProps } from '$self-define';

src/components/RouteWithSubRoutes/props.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/containers/AppContainer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// @flow
12
import React from 'react';
23
import { HashRouter as Router } from 'react-router-dom';
34
import { Provider } from 'react-redux';
4-
5+
import type { StoreWithInjectAble } from '$self-define';
56
type props = {
6-
routes: {},
7-
store: {}
7+
routes: React$Element<any>,
8+
store: StoreWithInjectAble
89
};
910

1011
class App extends React.Component<void, props, void> {

src/layouts/CoreLayout/CoreLayout.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import React, { PropTypes } from 'react';
2-
import Header from 'COMPONENTS/Header';
3-
import 'STYLES/core.less';
4-
import './CoreLayout.less';
1+
import React from 'react';
2+
import Header from '$components/Header';
3+
import RouteWithSubRoutes from '$components/RouteWithSubRoutes';
4+
import '$styles/core.less';
5+
import CoreLayoutModule from './CoreLayout.less';
56
import Counter from '../Counter';
7+
import type { StoreWithInjectAble, RouteProps } from '$self-define';
8+
type props = {
9+
routes: (store: StoreWithInjectAble) => Array<RouteProps>,
10+
store: StoreWithInjectAble
11+
};
612

7-
const CoreLayout = (props) => {
8-
const { children } = props;
13+
const CoreLayout = (props: props) => {
914
return (
1015
<div className="container text-center">
1116
<Counter />
1217
<Header />
13-
<div className="core-layout__viewport">{children}</div>
18+
<div className={CoreLayoutModule['core-layout__viewport']}>
19+
{props
20+
.routes(props.store)
21+
.map((route, i) => <RouteWithSubRoutes key={i} {...route} />)}
22+
</div>
1423
</div>
1524
);
1625
};
17-
CoreLayout.propTypes = {
18-
children: PropTypes.element.isRequired,
19-
};
2026
export default CoreLayout;

src/routes/Home/components/HomeView.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
// @flow
12
import React from 'react';
2-
import './HomeView.less';
3-
3+
import HomeViewLess from './HomeView.less';
44
export const HomeView = () => (
55
<div>
66
<h4>Welcome!</h4>
77
<img
88
alt="A magic!"
9-
className="magic"
9+
className={HomeViewLess.magic}
1010
src="/images/magic.png"
1111
/>
1212
</div>

src/routes/Home/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// @flow
12
export default () => import('./components/HomeView');
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { connect } from 'react-redux';
2-
import { actionCreatorMaps } from './reducers/increase';
2+
import { actionCreatorMaps as mapDispatchToProps } from './reducers/increase';
3+
import reducers from './reducers';
4+
import type { StoreWithInjectAble } from '$self-define';
35

46
import Increase from './components/Increase';
57

6-
const mapDispatchToProps = actionCreatorMaps;
7-
88
const mapStateToProps = state => ({
99
result: state.result,
1010
});
11-
export default connect(mapStateToProps, mapDispatchToProps)(Increase);
11+
export default (store: StoreWithInjectAble) => {
12+
store.injectAll(reducers);
13+
return connect(mapStateToProps, mapDispatchToProps)(Increase);
14+
};

0 commit comments

Comments
 (0)