This repository was archived by the owner on Aug 24, 2021. It is now read-only.
File tree 6 files changed +47
-7
lines changed
6 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 35
35
"eslint" : " ^2.13.1" ,
36
36
"react-hot-loader" : " ^3.0.0-beta.2" ,
37
37
"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"
39
41
},
40
42
"dependencies" : {
41
43
"mobx" : " ^2.2.2" ,
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import { observer } from 'mobx-react' ;
3
3
import DevTools from 'mobx-react-devtools' ;
4
+ import Something from './Something.jsx' ;
5
+ import Condition from './Condition.jsx' ;
4
6
5
- @observer
7
+ @observer ( [ 'appState' ] )
6
8
class App extends Component {
7
9
render ( ) {
8
10
return (
9
11
< div >
10
12
< button onClick = { this . onReset } >
11
13
Seconds passed: { this . props . appState . timer }
12
14
</ button >
15
+ < Condition >
16
+ < Something timer = { this . props . appState . timer } />
17
+ </ Condition >
13
18
< DevTools />
14
19
</ div >
15
20
) ;
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 ;
Original file line number Diff line number Diff line change @@ -2,24 +2,29 @@ import React from 'react';
2
2
import { render } from 'react-dom' ;
3
3
import { AppContainer } from 'react-hot-loader' ;
4
4
import AppState from './AppState' ;
5
- import App from './App' ;
5
+ import App from './components/App' ;
6
+ import { Provider } from 'mobx-react'
6
7
7
8
const appState = new AppState ( ) ;
8
9
9
10
render (
10
11
< AppContainer >
11
- < App appState = { appState } />
12
+ < Provider appState = { appState } >
13
+ < App />
14
+ </ Provider >
12
15
</ AppContainer > ,
13
16
document . getElementById ( 'root' )
14
17
) ;
15
18
16
19
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 ;
19
22
20
23
render (
21
24
< AppContainer >
22
- < NextApp appState = { appState } />
25
+ < Provider appState = { appState } >
26
+ < NextApp appState = { appState } />
27
+ </ Provider >
23
28
</ AppContainer > ,
24
29
document . getElementById ( 'root' )
25
30
) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ module.exports = {
25
25
test : / \. j s x ? $ / ,
26
26
loaders : [ 'babel' ] ,
27
27
include : path . join ( __dirname , 'src' )
28
+ } , {
29
+ test : / \. c s s $ / ,
30
+ loader : 'style!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]' ,
31
+ include : path . join ( __dirname , 'src' )
28
32
} ]
29
33
}
30
34
} ;
You can’t perform that action at this time.
0 commit comments