Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit 0da93f2

Browse files
committed
Update example to full ES2015-y goodness.
Fixes #221
1 parent 13447b0 commit 0da93f2

File tree

14 files changed

+82
-82
lines changed

14 files changed

+82
-82
lines changed

examples/.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
node_modules
2-
dist
1+
node_modules/
2+
dist/
3+
*.log

examples/basic/.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": ["es2015", "react", "stage-1"]
33
}

examples/basic/actions/count.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
const constants = require('../constants');
1+
import { INCREASE, DECREASE } from '../constants'
22

3-
function increase(n) {
3+
export function increase(n) {
44
return {
5-
type: constants.INCREASE,
5+
type: INCREASE,
66
amount: n
7-
};
7+
}
88
}
99

10-
function decrease(n) {
10+
export function decrease(n) {
1111
return {
12-
type: constants.DECREASE,
12+
type: DECREASE,
1313
amount: n
14-
};
14+
}
1515
}
16-
17-
module.exports = { increase, decrease };

examples/basic/app.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
import { createDevTools } from 'redux-devtools';
2-
import LogMonitor from 'redux-devtools-log-monitor';
3-
import DockMonitor from 'redux-devtools-dock-monitor';
1+
import { createDevTools } from 'redux-devtools'
2+
import LogMonitor from 'redux-devtools-log-monitor'
3+
import DockMonitor from 'redux-devtools-dock-monitor'
44

5-
const React = require('react');
6-
const ReactDOM = require('react-dom');
7-
const { applyMiddleware, compose, createStore, combineReducers } = require('redux');
8-
const { Provider } = require('react-redux');
9-
const { Router, Route, IndexRoute } = require('react-router');
10-
const createHistory = require('history/lib/createHashHistory');
11-
const { syncHistory, routeReducer } = require('redux-simple-router');
5+
import React from 'react'
6+
import ReactDOM from 'react-dom'
7+
import { applyMiddleware, compose, createStore, combineReducers } from 'redux'
8+
import { Provider } from 'react-redux'
9+
import { Router, Route, IndexRoute } from 'react-router'
10+
import createHistory from 'history/lib/createHashHistory'
11+
import { syncHistory, routeReducer } from 'redux-simple-router'
1212

13-
const reducers = require('./reducers');
14-
const { App, Home, Foo, Bar } = require('./components');
13+
import * as reducers from './reducers'
14+
import { App, Home, Foo, Bar } from './components'
1515

16-
const history = createHistory();
17-
const middleware = syncHistory(history);
18-
const reducer = combineReducers(Object.assign({}, reducers, {
16+
const history = createHistory()
17+
const middleware = syncHistory(history)
18+
const reducer = combineReducers({
19+
...reducers,
1920
routing: routeReducer
20-
}));
21+
})
2122

2223
const DevTools = createDevTools(
23-
<DockMonitor toggleVisibilityKey='ctrl-h'
24-
changePositionKey='ctrl-q'>
25-
<LogMonitor theme='tomorrow' />
24+
<DockMonitor toggleVisibilityKey="ctrl-h"
25+
changePositionKey="ctrl-q">
26+
<LogMonitor theme="tomorrow" />
2627
</DockMonitor>
27-
);
28+
)
2829

2930
const finalCreateStore = compose(
3031
applyMiddleware(middleware),
3132
DevTools.instrument()
32-
)(createStore);
33-
const store = finalCreateStore(reducer);
34-
middleware.listenForReplays(store);
33+
)(createStore)
34+
const store = finalCreateStore(reducer)
35+
middleware.listenForReplays(store)
3536

3637
ReactDOM.render(
3738
<Provider store={store}>
@@ -47,4 +48,4 @@ ReactDOM.render(
4748
</div>
4849
</Provider>,
4950
document.getElementById('mount')
50-
);
51+
)

examples/basic/components/App.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const React = require('react');
2-
const { Link } = require('react-router');
3-
const { connect } = require('react-redux');
4-
const { routeActions } = require('redux-simple-router');
1+
import React from 'react'
2+
import { Link } from 'react-router'
3+
import { connect } from 'react-redux'
4+
import { routeActions } from 'redux-simple-router'
55

66
function App({ push, children }) {
77
return (
@@ -18,12 +18,12 @@ function App({ push, children }) {
1818
<div>
1919
<button onClick={() => push('/foo')}>Go to /foo</button>
2020
</div>
21-
<div style={{marginTop: '1.5em'}}>{children}</div>
21+
<div style={{ marginTop: '1.5em' }}>{children}</div>
2222
</div>
23-
);
24-
};
23+
)
24+
}
2525

26-
module.exports = connect(
26+
export default connect(
2727
null,
28-
{ push: routeActions.push }
29-
)(App);
28+
routeActions
29+
)(App)

examples/basic/components/Bar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const React = require('react');
1+
import React from 'react'
22

3-
module.exports = function Bar() {
4-
return <div>And I am Bar!</div>;
3+
export default function Bar() {
4+
return <div>And I am Bar!</div>
55
}

examples/basic/components/Foo.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const React = require('react');
1+
import React from 'react'
22

3-
module.exports = function Foo() {
4-
return <div>I am Foo!</div>;
3+
export default function Foo() {
4+
return <div>I am Foo!</div>
55
}

examples/basic/components/Home.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const React = require('react');
2-
const { connect } = require('react-redux');
3-
const { increase, decrease } = require('../actions/count');
1+
import React from 'react'
2+
import { connect } from 'react-redux'
3+
import { increase, decrease } from '../actions/count'
44

55
function Home({ number, increase, decrease }) {
66
return (
@@ -10,10 +10,10 @@ function Home({ number, increase, decrease }) {
1010
<button onClick={() => increase(1)}>Increase</button>
1111
<button onClick={() => decrease(1)}>Decrease</button>
1212
</div>
13-
);
14-
};
13+
)
14+
}
1515

16-
module.exports = connect(
16+
export default connect(
1717
state => ({ number: state.count.number }),
1818
{ increase, decrease }
19-
)(Home);
19+
)(Home)

examples/basic/components/index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
const App = require('./App');
2-
const Home = require('./Home');
3-
const Foo = require('./Foo');
4-
const Bar = require('./Bar');
5-
6-
module.exports = { App, Home, Foo, Bar };
1+
export App from './App'
2+
export Home from './Home'
3+
export Foo from './Foo'
4+
export Bar from './Bar'

examples/basic/constants.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11

2-
module.exports = {
3-
INCREASE: 'INCREASE',
4-
DECREASE: 'DECREASE'
5-
}
2+
export const INCREASE = 'INCREASE'
3+
export const DECREASE = 'DECREASE'

examples/basic/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "rsr-basic-example",
33
"version": "0.0.0",
4+
"repository": "rackt/redux-simple-router",
5+
"license": "MIT",
46
"dependencies": {
57
"history": "^1.14.0",
68
"react": "^0.14.2",
@@ -12,9 +14,14 @@
1214
},
1315
"devDependencies": {
1416
"babel-core": "^6.1.21",
17+
"babel-eslint": "^5.0.0-beta6",
1518
"babel-loader": "^6.2.0",
1619
"babel-preset-es2015": "^6.1.18",
1720
"babel-preset-react": "^6.1.18",
21+
"babel-preset-stage-1": "^6.3.13",
22+
"eslint": "^1.10.3",
23+
"eslint-config-rackt": "^1.1.1",
24+
"eslint-plugin-react": "^3.15.0",
1825
"redux-devtools": "^3.0.0",
1926
"redux-devtools-dock-monitor": "^1.0.1",
2027
"redux-devtools-log-monitor": "^1.0.1",

examples/basic/reducers/count.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
const constants = require('../constants');
1+
import { INCREASE, DECREASE } from '../constants'
22

33
const initialState = {
44
number: 1
55
}
66

7-
function update(state = initialState, action) {
8-
if(action.type === constants.INCREASE) {
9-
return { number: state.number + action.amount };
7+
export default function update(state = initialState, action) {
8+
if(action.type === INCREASE) {
9+
return { number: state.number + action.amount }
1010
}
11-
else if(action.type === constants.DECREASE) {
12-
return { number: state.number - action.amount };
11+
else if(action.type === DECREASE) {
12+
return { number: state.number - action.amount }
1313
}
14-
return state;
14+
return state
1515
}
16-
17-
module.exports = update;

examples/basic/reducers/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
const count = require('./count');
2-
3-
module.exports = { count };
1+
export count from './count'

examples/basic/webpack.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
const path = require('path');
23

34
module.exports = {
@@ -9,7 +10,7 @@ module.exports = {
910
module: {
1011
loaders: [{
1112
test: /\.js$/,
12-
loaders: ['babel?presets[]=react,presets[]=es2015'],
13+
loader: 'babel',
1314
exclude: /node_modules/,
1415
include: __dirname
1516
}]

0 commit comments

Comments
 (0)