Skip to content

Commit 8bc9eba

Browse files
committed
lessons 12 finish
1 parent 2e251b1 commit 8bc9eba

File tree

9 files changed

+116
-26
lines changed

9 files changed

+116
-26
lines changed

lessons/01-setting-up/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Repo from './modules/Repo'
99
import Home from './modules/Home'
1010

1111
render((
12-
<Router history={browserHistory}>
12+
<Router history={hashHistory}>
1313
<Route path="/" component={App}>
1414
<IndexRoute component={Home}/>
1515
<Route path="/repos" component={Repos}>

lessons/01-setting-up/modules/Repos.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
import React, { Component } from 'react';
22
import {Link} from 'react-router';
3-
import NavLink from './NavLink'
3+
import NavLink from './NavLink';
4+
import { hashHistory } from 'react-router';
45

56
class Repos extends Component {
7+
//
8+
// contextType = {
9+
// router : React.PropTypes.object
10+
// }
11+
12+
// constructor(props, context) {
13+
// super(...arguments);
14+
// this.context = context;
15+
// }
16+
17+
handleSubmit(event) {
18+
//console.log(this)
19+
event.preventDefault();
20+
const userName = event.target.elements[0].value;
21+
const repo = event.target.elements[1].value;
22+
const path = `/repos/${userName}/${repo}`;
23+
//console.log(path)
24+
//hashHistory.push(path)
25+
this.context.router.push(path)
26+
}
27+
628
render(){
729
return (
830
<div>
@@ -11,6 +33,14 @@ class Repos extends Component {
1133
<ul>
1234
<li><NavLink to='repos/reactjs/react-router'>React Router</NavLink></li>
1335
<li><NavLink to='repos/facebook/react'>React</NavLink></li>
36+
37+
<li>
38+
<form onSubmit={this.handleSubmit.bind(this)}>
39+
<input type='text' placeholder='userName'/> / {' '}
40+
<input type='text' placeholder='repo'/>{' '}
41+
<button type='submit'>GO</button>
42+
</form>
43+
</li>
1444
</ul>
1545

1646
{this.props.children}
@@ -19,4 +49,8 @@ class Repos extends Component {
1949
}
2050
}
2151

52+
Repos.contextTypes = {
53+
router : React.PropTypes.object
54+
}
55+
2256
export default Repos;

lessons/01-setting-up/npm-debug.log

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/node',
3+
1 verbose cli '/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/npm',
4+
1 verbose cli 'start' ]
5+
2 info using [email protected]
6+
3 info using [email protected]
7+
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
8+
5 info prestart [email protected]
9+
6 info start [email protected]
10+
7 verbose unsafe-perm in lifecycle true
11+
8 info [email protected] Failed to exec start script
12+
9 verbose stack Error: [email protected] start: `if-env NODE_ENV=production && npm run start:prod || npm run start:dev`
13+
9 verbose stack Exit status 1
14+
9 verbose stack at EventEmitter.<anonymous> (/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/lib/node_modules/npm/lib/utils/lifecycle.js:217:16)
15+
9 verbose stack at emitTwo (events.js:87:13)
16+
9 verbose stack at EventEmitter.emit (events.js:172:7)
17+
9 verbose stack at ChildProcess.<anonymous> (/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/lib/node_modules/npm/lib/utils/spawn.js:24:14)
18+
9 verbose stack at emitTwo (events.js:87:13)
19+
9 verbose stack at ChildProcess.emit (events.js:172:7)
20+
9 verbose stack at maybeClose (internal/child_process.js:829:16)
21+
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
22+
10 verbose pkgid [email protected]
23+
11 verbose cwd /home/r2fresh-kt-ubuntu/workspace/react-router-tutorial/lessons/01-setting-up
24+
12 error Linux 4.4.0-36-generic
25+
13 error argv "/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/node" "/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/npm" "start"
26+
14 error node v4.5.0
27+
15 error npm v2.15.9
28+
16 error code ELIFECYCLE
29+
17 error [email protected] start: `if-env NODE_ENV=production && npm run start:prod || npm run start:dev`
30+
17 error Exit status 1
31+
18 error Failed at the [email protected] start script 'if-env NODE_ENV=production && npm run start:prod || npm run start:dev'.
32+
18 error This is most likely a problem with the tutorial package,
33+
18 error not with npm itself.
34+
18 error Tell the author that this fails on your system:
35+
18 error if-env NODE_ENV=production && npm run start:prod || npm run start:dev
36+
18 error You can get information on how to open an issue for this project with:
37+
18 error npm bugs tutorial
38+
18 error Or if that isn't available, you can get their info via:
39+
18 error
40+
18 error npm owner ls tutorial
41+
18 error There is likely additional logging output above.
42+
19 verbose exit [ 1, true ]

lessons/01-setting-up/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"start" : "if-env NODE_ENV=production && npm run start:prod || npm run start:dev",
8-
"start:dev" : "webpack-dev-server --inline --content-base . --history-api-fallback",
8+
"start:dev" : "webpack-dev-server --inline --content-base public --history-api-fallback",
99
"start:prod" : "webpack && node server.js"
1010
},
1111
"author": "",

lessons/01-setting-up/index.html renamed to lessons/01-setting-up/public/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
<link rel="stylesheet" href="/index.css">
55
<title>My First React Router App</title>
66
<div id=app></div>
7-
<div>aaaa</div>
8-
<!--<script src="/bundle.js"></script>-->
7+
<script src="/bundle.js"></script>

lessons/01-setting-up/server.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
var express = require('express')
22
var path = require('path')
3+
var compression = require('compression')
34

45
var app = express()
56

6-
app.use(express.static(__dirname))
7+
app.use(compression())
8+
9+
// serve our static stuff like index.css
10+
app.use(express.static(path.join(__dirname, 'public')))
711

812
app.get('*', function(req, res) {
9-
res.sendFile(path.join(__dirname, 'index.html'))
13+
res.sendFile(path.join(__dirname, 'public', 'index.html'))
1014
})
1115

1216
var PORT = process.env.PORT || 8080
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1+
var webpack = require('webpack');
2+
13
module.exports = {
2-
entry: './index.js',
4+
entry: './index.js',
35

4-
output: {
5-
path : 'public',
6-
filename: 'bundle.js',
7-
publicPath: '/'
8-
},
6+
output: {
7+
path : 'public',
8+
filename: 'bundle.js',
9+
publicPath: '/'
10+
},
911

10-
module: {
11-
loaders: [
12-
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' }
13-
]
14-
}
12+
module: {
13+
loaders: [
14+
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?presets[]=es2015&presets[]=react' }
15+
]
16+
},
17+
plugins: process.env.NODE_ENV === 'production' ? [
18+
new webpack.optimize.DedupePlugin(),
19+
new webpack.optimize.OccurrenceOrderPlugin(),
20+
new webpack.optimize.UglifyJsPlugin({
21+
compress:{
22+
warnings : false
23+
}
24+
})
25+
] : [],
1526
}

npm-debug.log

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
0 info it worked if it ends with ok
2-
1 verbose cli [ '/Users/r2fresh/.nvm/versions/v4.5.0/bin/node',
3-
1 verbose cli '/Users/r2fresh/.nvm/versions/v4.5.0/bin/npm',
2+
1 verbose cli [ '/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/node',
3+
1 verbose cli '/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/npm',
44
1 verbose cli 'start' ]
55
2 info using [email protected]
66
3 info using [email protected]
7-
4 verbose stack Error: ENOENT: no such file or directory, open '/Users/r2fresh/workspace/react-router-tutorial/package.json'
7+
4 verbose stack Error: ENOENT: no such file or directory, open '/home/r2fresh-kt-ubuntu/workspace/react-router-tutorial/package.json'
88
4 verbose stack at Error (native)
9-
5 verbose cwd /Users/r2fresh/workspace/react-router-tutorial
10-
6 error Darwin 15.6.0
11-
7 error argv "/Users/r2fresh/.nvm/versions/v4.5.0/bin/node" "/Users/r2fresh/.nvm/versions/v4.5.0/bin/npm" "start"
9+
5 verbose cwd /home/r2fresh-kt-ubuntu/workspace/react-router-tutorial
10+
6 error Linux 4.4.0-36-generic
11+
7 error argv "/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/node" "/home/r2fresh-kt-ubuntu/.nvm/v4.5.0/bin/npm" "start"
1212
8 error node v4.5.0
1313
9 error npm v2.15.9
14-
10 error path /Users/r2fresh/workspace/react-router-tutorial/package.json
14+
10 error path /home/r2fresh-kt-ubuntu/workspace/react-router-tutorial/package.json
1515
11 error code ENOENT
1616
12 error errno -2
1717
13 error syscall open
18-
14 error enoent ENOENT: no such file or directory, open '/Users/r2fresh/workspace/react-router-tutorial/package.json'
18+
14 error enoent ENOENT: no such file or directory, open '/home/r2fresh-kt-ubuntu/workspace/react-router-tutorial/package.json'
1919
14 error enoent This is most likely not a problem with npm itself
2020
14 error enoent and is related to npm not being able to find a file.
2121
15 verbose exit [ -2, true ]

0 commit comments

Comments
 (0)