Skip to content

Commit 1278be6

Browse files
committed
Lesson 15
1 parent 49152f2 commit 1278be6

File tree

4 files changed

+76
-15
lines changed

4 files changed

+76
-15
lines changed

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
"babel-loader": "^6.2.4",
1616
"babel-preset-es2015": "^6.9.0",
1717
"babel-preset-react": "^6.5.0",
18+
"babel-standalone": "^6.7.7",
1819
"react": "^15.1.0",
1920
"react-dom": "^15.1.0"
2021
},
2122
"devDependencies": {
2223
"babel": "^6.5.2",
24+
"css-loader": "^0.23.1",
2325
"standard": "^7.1.1",
26+
"style-loader": "^0.13.1",
2427
"webpack": "^1.13.1",
2528
"webpack-dev-server": "^1.14.1"
2629
}

web_modules/app/index.js

+31-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
import React, { Component } from 'react'
2+
import { transform } from 'babel-standalone'
3+
import './styles.css'
24

35
class App extends Component {
46
constructor () {
57
super()
68
this.state = {
7-
people: [
8-
{id: 1, name: 'David'},
9-
{id: 2, name: 'Jordan'},
10-
{id: 3, name: 'Renick'},
11-
{id: 4, name: 'Galilee'},
12-
{id: 5, name: 'Magdalene'}
13-
]
9+
input: '/* add your jsx here */',
10+
output: '',
11+
error: ''
1412
}
13+
this.update = this.update.bind(this)
1514
}
1615

17-
render () {
18-
const people = this.state.people.map((person) => {
19-
return <Person key={person.id} person={person} />
20-
})
16+
update (e) {
17+
const code = e.target.value
2118

22-
return <div>{people}</div>
19+
try {
20+
this.setState({
21+
output: transform(code, {
22+
presets: ['es2015-loose', 'react', 'stage-0']
23+
}).code,
24+
error: ''
25+
})
26+
} catch (err) {
27+
this.setState({ error: err.message })
28+
}
2329
}
24-
}
2530

26-
const Person = ({ person: { id, name } }) => {
27-
return <div>{id}. {name}</div>
31+
render () {
32+
const { input, output, error } = this.state
33+
34+
return (
35+
<div>
36+
<header>{error}</header>
37+
<div className='container'>
38+
<textarea defaultValue={input} onChange={this.update}></textarea>
39+
<pre>{output}</pre>
40+
</div>
41+
</div>
42+
)
43+
}
2844
}
2945

3046
export default App

web_modules/app/styles.css

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
font-family: monospace;
5+
}
6+
7+
header {
8+
display: block;
9+
height: 10vh;
10+
overflow: auto;
11+
background: pink;
12+
color: red;
13+
font-size: 28px;
14+
}
15+
16+
.container {
17+
height: 90vh;
18+
display: -webkit-flex;
19+
display: -moz-flex;
20+
display: -ms-flex;
21+
display: -o-flex;
22+
display: flex;
23+
}
24+
25+
pre {
26+
background: #f8f8f8;
27+
}
28+
29+
pre, textarea {
30+
width: 50%;
31+
font-family: monospace;;
32+
font-size: 28px;
33+
margin: 0;
34+
padding: 10px;
35+
color: #222;
36+
}
37+
38+
textarea:focus { outline: 0; }

webpack.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module.exports = {
1717
query: {
1818
presets: ['es2015', 'react']
1919
}
20+
},
21+
{
22+
test: /\.css$/,
23+
loaders: ['style', 'css']
2024
}
2125
]
2226
}

0 commit comments

Comments
 (0)