Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Commit 455a7ae

Browse files
committed
Repro timing issue.
1 parent 3cf2426 commit 455a7ae

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"eslint": "^2.13.1",
3636
"react-hot-loader": "^3.0.0-beta.2",
3737
"webpack": "^1.13.1",
38-
"webpack-dev-server": "^1.14.1"
38+
"webpack-dev-server": "^1.14.1",
39+
"css-loader": "^0.15.1",
40+
"style-loader": "^0.12.3"
3941
},
4042
"dependencies": {
4143
"mobx": "^2.2.2",

src/App.jsx renamed to src/components/App.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import React, { Component } from 'react';
22
import { observer } from 'mobx-react';
33
import DevTools from 'mobx-react-devtools';
4+
import Something from './Something.jsx';
5+
import Condition from './Condition.jsx';
46

5-
@observer
7+
@observer(['appState'])
68
class App extends Component {
79
render() {
810
return (
911
<div>
1012
<button onClick={this.onReset}>
1113
Seconds passed: {this.props.appState.timer}
1214
</button>
15+
<Condition>
16+
<Something timer={this.props.appState.timer} />
17+
</Condition>
1318
<DevTools />
1419
</div>
1520
);

src/components/Condition.jsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { Component } from 'react';
2+
import { observer } from 'mobx-react';
3+
4+
@observer(['appState'])
5+
export default class Condition extends Component {
6+
render() {
7+
return this.props.appState.timer > 3 ?
8+
//React.cloneElement(this.props.children) :
9+
this.props.children :
10+
<span>Nothing</span>;
11+
}
12+
}

src/components/Something.jsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { Component } from 'react';
2+
import { observer } from 'mobx-react';
3+
4+
@observer
5+
class Something extends Component {
6+
render() {
7+
debugger; // this.props.timer is 3 but this doesn't render until the timer value is 4
8+
return <span>{this.props.timer}</span>;
9+
}
10+
}
11+
12+
export default Something;

src/index.jsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@ import React from 'react';
22
import { render } from 'react-dom';
33
import { AppContainer } from 'react-hot-loader';
44
import AppState from './AppState';
5-
import App from './App';
5+
import App from './components/App';
6+
import { Provider } from 'mobx-react'
67

78
const appState = new AppState();
89

910
render(
1011
<AppContainer>
11-
<App appState={appState} />
12+
<Provider appState={appState}>
13+
<App />
14+
</Provider>
1215
</AppContainer>,
1316
document.getElementById('root')
1417
);
1518

1619
if (module.hot) {
17-
module.hot.accept('./App', () => {
18-
const NextApp = require('./App').default;
20+
module.hot.accept('./components/App', () => {
21+
const NextApp = require('./components/App').default;
1922

2023
render(
2124
<AppContainer>
22-
<NextApp appState={appState} />
25+
<Provider appState={appState}>
26+
<NextApp appState={appState} />
27+
</Provider>
2328
</AppContainer>,
2429
document.getElementById('root')
2530
);

webpack.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ module.exports = {
2525
test: /\.jsx?$/,
2626
loaders: ['babel'],
2727
include: path.join(__dirname, 'src')
28+
}, {
29+
test: /\.css$/,
30+
loader: 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
31+
include: path.join(__dirname, 'src')
2832
}]
2933
}
3034
};

0 commit comments

Comments
 (0)