Skip to content

Commit

Permalink
Totally rewrite all stateless components(pure function)
Browse files Browse the repository at this point in the history
into stateful components(eg. ES6 class component).

gaearon/react-transform-hmr#6
  • Loading branch information
hbin committed Dec 4, 2015
1 parent 051e1be commit 3633762
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 80 deletions.
16 changes: 10 additions & 6 deletions src/containers/Bar.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import React, { Component } from 'react';

import { Link } from 'react-router';

const Bar = () => (
<div>
I am bar. Let's go to <Link to="foo">Foo</Link>
</div>
);
class Bar extends Component {
render() {
return (
<div>
I am bar Let's go to <Link to="foo">Foo</Link>
</div>
);
}
}

export default Bar;
2 changes: 1 addition & 1 deletion src/containers/DevTools.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createDevTools } from 'redux-devtools';
import LogMonitor from 'redux-devtools-log-monitor';
import DockMonitor from 'redux-devtools-dock-monitor';

const DevTools = createDevTools(
const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey='H'
changePositionKey='Q'>
<LogMonitor />
Expand Down
16 changes: 10 additions & 6 deletions src/containers/Foo.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import React, { Component } from 'react';

import { Link } from 'react-router';

const Foo = () => (
<div>
I am foo. Let's go to <Link to="/bar">Bar</Link>
</div>
);
class Foo extends Component {
render() {
return (
<div>
I am foo. Let's go to <Link to="/bar">Bar</Link>
</div>
);
}
}

export default Foo;
31 changes: 17 additions & 14 deletions src/containers/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React from 'react';
import React, { Component } from 'react';

import { Link } from 'react-router';

const Home = ({
children
}) => (
<div>
<Link to="/todo">Go to Todo</Link>
{' | '}
<Link to="/foo">Go to Foo</Link>
{' | '}
<Link to="/bar">Go to Bar</Link>
<hr />
{children}
</div>
);
class Home extends Component {
render() {
const { children } = this.props;
return (
<div>
<Link to="/todo">Go to Todo</Link>
{' | '}
<Link to="/foo">Go to Foo</Link>
{' | '}
<Link to="/bar">Go to Bar</Link>
<hr />
{children}
</div>
);
}
};

export default Home;
19 changes: 0 additions & 19 deletions src/containers/Root/Root.dev.jsx

This file was deleted.

17 changes: 0 additions & 17 deletions src/containers/Root/Root.prod.jsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/containers/Root/index.js

This file was deleted.

20 changes: 12 additions & 8 deletions src/containers/TodoApp.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react';
import React, { Component } from 'react';

import AddTodo from '../components/AddTodo';
import VisibleTodoList from '../components/TodoList';
import Footer from '../components/Footer';

const TodoApp = () => (
<div>
<AddTodo />
<VisibleTodoList />
<Footer />
</div>
);
class TodoApp extends Component {
render() {
return (
<div>
<AddTodo />
<VisibleTodoList />
<Footer />
</div>
);
}
}

export default TodoApp;
15 changes: 13 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ import createBrowserHistory from 'history/lib/createBrowserHistory';
import createRoutes from './routes';
import configureStore from './store';

import Root from './containers/Root';
let reduxTools = null;
if (__DEVTOOLS__) {
const DevTools = require('./containers/DevTools');
reduxTools = (
<DevTools />
)
}

const history = createBrowserHistory();
const routes = createRoutes();
const store = configureStore();

render(
<Root store={store} history={history} routes={routes} />,
<Provider store={store}>
<div>
<Router history={history} routes={routes} />
{reduxTools}
</div>
</Provider>,
document.getElementById('container')
);
3 changes: 2 additions & 1 deletion webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = {
'process.env': {
// Useful to reduce the size of client-side libraries, e.g. react
NODE_ENV: JSON.stringify('development')
}
},
__DEVTOOLS__: true
}),
new HtmlWebpackPlugin({
title: 'Webpack React Biolerplate',
Expand Down
3 changes: 2 additions & 1 deletion webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = {
'process.env': {
// Useful to reduce the size of client-side libraries, e.g. react
NODE_ENV: JSON.stringify('production')
}
},
__DEVTOOLS__: false
}),
new HtmlWebpackPlugin({
title: 'Webpack React Biolerplate',
Expand Down

0 comments on commit 3633762

Please sign in to comment.