Skip to content

Commit

Permalink
Start playing
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Aug 22, 2015
1 parent f66496a commit 3550ec6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
75 changes: 74 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,82 @@
import React, { Component } from 'react';

class RendererA extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
setInterval(() => this.tick(), 10);
}

tick() {
this.setState({
counter: this.state.counter + 1
});
}

render() {
return (
<span style={{ color: 'red' }}>
{this.state.counter}, {this.props.children}
</span>
);
}
}

class RendererB extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
setInterval(() => this.tick(), 10);
}

tick() {
this.setState({
counter: this.state.counter + 1
});
}

render() {
return (
<span style={{ color: 'green' }}>
{this.state.counter}, {this.props.children}
</span>
);
}
}

function makeSomething(Renderer, speed) {
return class Something extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
setInterval(() => this.tick(), speed);
}

tick() {
this.setState({
counter: this.state.counter + 1
});
}

render() {
return <h1><Renderer>{this.state.counter}</Renderer></h1>;
}
};
}

let Something1 = makeSomething(RendererA, 10);
let Something2 = makeSomething(RendererB, 1000);

export default class App extends Component {
render() {
return (
<h1>Hello, world.</h1>
<div>
<Something1 />
<Something2 />
nice
</div>
);
}
}

module.hot.accept();
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel'],
loaders: ['babel'],
include: path.join(__dirname, 'src')
}]
}
Expand Down

0 comments on commit 3550ec6

Please sign in to comment.