Skip to content

Commit a096d89

Browse files
committed
ES6, react, and react-router updates
1 parent 55ad238 commit a096d89

File tree

20 files changed

+213
-110
lines changed

20 files changed

+213
-110
lines changed

lessons/05-active-links/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ import { Link } from 'react-router';
6565

6666
export default extends React.Component {
6767
render() {
68-
return <Link {...this.props} activeClassName="active"/>
68+
return <Link {...this.props} activeClassName="active"/>;
6969
}
7070
})
7171
```

lessons/06-params/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ First we need a component to render at the route, make a new file at
2626

2727
```js
2828
// modules/Repo.js
29-
import React from 'react'
29+
import React from 'react';
3030

31-
export default React.createClass({
31+
export default class Repo extends React.Component {
3232
render() {
3333
return (
3434
<div>
3535
<h2>{this.props.params.repoName}</h2>
3636
</div>
3737
)
3838
}
39-
})
39+
}
4040
```
4141

4242
Now open up `index.js` and add the new route.
4343

4444
```js
4545
// ...
4646
// import Repo
47-
import Repo from './modules/Repo'
47+
import Repo from './modules/Repo';
4848

4949
render((
5050
<Router history={hashHistory}>
@@ -55,16 +55,16 @@ render((
5555
<Route path="/about" component={About}/>
5656
</Route>
5757
</Router>
58-
), document.getElementById('app'))
58+
), document.getElementById('app'));
5959
```
6060

6161
Now we can add some links to this new route in `Repos.js`.
6262

6363
```js
6464
// Repos.js
65-
import { Link } from 'react-router'
65+
import { Link } from 'react-router';
6666
// ...
67-
export default React.createClass({
67+
export default class Repos extends React.Component {
6868
render() {
6969
return (
7070
<div>
@@ -77,9 +77,9 @@ export default React.createClass({
7777
</ul>
7878

7979
</div>
80-
)
80+
);
8181
}
82-
})
82+
}
8383
```
8484

8585
Now go test your links out. Note that the parameter name in the route

lessons/08-index-routes/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ component and then talk about how to render it at `/`.
66

77
```js
88
// modules/Home.js
9-
import React from 'react'
9+
import React from 'react';
1010

11-
export default React.createClass({
11+
export default class Home extends React.Component {
1212
render() {
1313
return <div>Home</div>
1414
}
15-
})
15+
}
1616
```
1717

1818
One option is to see if we have any children in `App`, and if not,
1919
render `Home`:
2020

2121
```js
2222
// modules/App.js
23-
import Home from './Home'
23+
import Home from './Home';
2424

2525
// ...
2626
<div>
@@ -48,9 +48,9 @@ Let's add a new route to `index.js`.
4848
// index.js
4949
// new imports:
5050
// add `IndexRoute` to 'react-router' imports
51-
import { Router, Route, hashHistory, IndexRoute } from 'react-router'
51+
import { Router, Route, hashHistory, IndexRoute } from 'react-router';
5252
// and the Home component
53-
import Home from './modules/Home'
53+
import Home from './modules/Home';
5454

5555
// ...
5656

@@ -67,7 +67,7 @@ render((
6767
<Route path="/about" component={About}/>
6868
</Route>
6969
</Router>
70-
), document.getElementById('app'))
70+
), document.getElementById('app'));
7171
```
7272

7373
Now open [http://localhost:8080](http://localhost:8080) and you'll see the new component is

lessons/09-index-links/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ First let's use the `IndexLink` instead of `NavLink`
2727

2828
```js
2929
// App.js
30-
import { IndexLink } from 'react-router'
30+
import { IndexLink } from 'react-router';
3131

3232
// ...
3333
<li><IndexLink to="/" activeClassName="active">Home</IndexLink></li>

lessons/10-clean-urls/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Open up `index.js` and import `browserHistory` instead of `hashHistory`.
1515
// index.js
1616
// ...
1717
// bring in `browserHistory` instead of `hashHistory`
18-
import { Router, Route, browserHistory, IndexRoute } from 'react-router'
18+
import { Router, Route, browserHistory, IndexRoute } from 'react-router';
1919

2020
render((
2121
<Router history={browserHistory}>
2222
{/* ... */}
2323
</Router>
24-
), document.getElementById('app'))
24+
), document.getElementById('app'));
2525
```
2626

2727
Now go click around and admire your clean URLs.

lessons/11-productionish-server/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ first attempt:
4646

4747
```js
4848
// server.js
49-
var express = require('express')
50-
var path = require('path')
49+
var express = require('express');
50+
var path = require('path');
5151

52-
var app = express()
52+
var app = express();
5353

5454
// serve our static stuff like index.css
55-
app.use(express.static(__dirname))
55+
app.use(express.static(__dirname));
5656

5757
// send all requests to index.html so browserHistory in React Router works
5858
app.get('*', function (req, res) {
59-
res.sendFile(path.join(__dirname, 'index.html'))
59+
res.sendFile(path.join(__dirname, 'index.html'));
6060
})
6161

6262
var PORT = process.env.PORT || 8080
6363
app.listen(PORT, function() {
64-
console.log('Production Express server running at localhost:' + PORT)
65-
})
64+
console.log('Production Express server running at localhost:' + PORT);
65+
});
6666
```
6767

6868
Now run:
@@ -88,12 +88,12 @@ assets:
8888
// server.js
8989
// ...
9090
// add path.join here
91-
app.use(express.static(path.join(__dirname, 'public')))
91+
app.use(express.static(path.join(__dirname, 'public')));
9292

9393
// ...
9494
app.get('*', function (req, res) {
9595
// and drop 'public' in the middle of here
96-
res.sendFile(path.join(__dirname, 'public', 'index.html'))
96+
res.sendFile(path.join(__dirname, 'public', 'index.html'));
9797
})
9898
```
9999

@@ -127,7 +127,7 @@ express.
127127
// webpack.config.js
128128

129129
// make sure to import this
130-
var webpack = require('webpack')
130+
var webpack = require('webpack');
131131

132132
module.exports = {
133133
// ...
@@ -141,19 +141,19 @@ module.exports = {
141141
] : [],
142142

143143
// ...
144-
}
144+
};
145145
```
146146

147147
And compression in express:
148148

149149
```js
150150
// server.js
151151
// ...
152-
var compression = require('compression')
152+
var compression = require('compression');
153153

154-
var app = express()
154+
var app = express();
155155
// must be first!
156-
app.use(compression())
156+
app.use(compression());
157157
```
158158

159159
Now go start your server in production mode:

lessons/12-navigating/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["react", "es2015"]
3+
}

lessons/12-navigating/.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

lessons/12-navigating/.eslintrc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:import/errors",
5+
"plugin:import/warnings"
6+
],
7+
"plugins": [
8+
"react"
9+
],
10+
"parserOptions": {
11+
"ecmaVersion": 6,
12+
"sourceType": "module",
13+
"ecmaFeatures": {
14+
"jsx": true
15+
}
16+
},
17+
"env": {
18+
"es6": true,
19+
"browser": true,
20+
"node": true,
21+
"jquery": true,
22+
"mocha": true
23+
},
24+
"rules": {
25+
"quotes": 0,
26+
"no-console": 1,
27+
"no-debugger": 1,
28+
"no-var": 1,
29+
"indent": ["error", 2],
30+
"semi": [1, "always"],
31+
"no-trailing-spaces": 0,
32+
"eol-last": 0,
33+
"no-unused-vars": 0,
34+
"no-underscore-dangle": 0,
35+
"no-alert": 0,
36+
"no-lone-blocks": 0,
37+
"jsx-quotes": 1,
38+
"react/display-name": [ 1, {"ignoreTranspilerName": false }],
39+
"react/forbid-prop-types": [1, {"forbid": ["any"]}],
40+
"react/jsx-boolean-value": 1,
41+
"react/jsx-closing-bracket-location": 0,
42+
"react/jsx-curly-spacing": 1,
43+
"react/jsx-indent-props": 0,
44+
"react/jsx-key": 1,
45+
"react/jsx-max-props-per-line": 0,
46+
"react/jsx-no-bind": 1,
47+
"react/jsx-no-duplicate-props": 1,
48+
"react/jsx-no-literals": 0,
49+
"react/jsx-no-undef": 1,
50+
"react/jsx-pascal-case": 1,
51+
"react/jsx-sort-prop-types": 0,
52+
"react/jsx-sort-props": 0,
53+
"react/jsx-uses-react": 1,
54+
"react/jsx-uses-vars": 1,
55+
"react/no-danger": 1,
56+
"react/no-did-mount-set-state": 1,
57+
"react/no-did-update-set-state": 1,
58+
"react/no-direct-mutation-state": 1,
59+
"react/no-multi-comp": 1,
60+
"react/no-set-state": 0,
61+
"react/no-unknown-property": 1,
62+
"react/prefer-es6-class": 1,
63+
"react/prop-types": 1,
64+
"react/react-in-jsx-scope": 1,
65+
"react/require-extension": 1,
66+
"react/self-closing-comp": 1,
67+
"react/sort-comp": 1,
68+
"react/wrap-multilines": 1
69+
}
70+
}

0 commit comments

Comments
 (0)