22
33const _ = require ( 'lodash' ) ;
44const React = require ( 'react' ) ;
5- const { createContainer } = require ( 'sovereign' ) ;
65
76const styles = require ( './styles' ) ;
87const transmissionStore = require ( '../../src/stores/transmission' ) ;
98
109class Indicators extends React . Component {
1110
11+ constructor ( ) {
12+ this . _updateIndicators = this . _updateIndicators . bind ( this ) ;
13+ }
14+
15+ _updateIndicators ( ) {
16+ const { flashRx, flashTx } = transmissionStore . getState ( ) ;
17+ if ( flashRx ) {
18+ this . rx . style . backgroundColor = styles . rx . backgroundColor ;
19+ } else {
20+ this . rx . style . backgroundColor = styles . indicator . backgroundColor ;
21+ }
22+ if ( flashTx ) {
23+ this . tx . style . backgroundColor = styles . tx . backgroundColor ;
24+ } else {
25+ this . tx . style . backgroundColor = styles . indicator . backgroundColor ;
26+ }
27+ }
28+
1229 componentDidMount ( ) {
1330 var parent = React . findDOMNode ( this ) ;
1431 var tx = this . tx = document . createElement ( 'span' ) ;
@@ -23,64 +40,28 @@ class Indicators extends React.Component {
2340 tx . style [ name ] = style ;
2441 rx . style [ name ] = style ;
2542 } ) ;
26- console . log ( 'componentDidMount' , tx , rx , tx . style ) ;
43+
44+ transmissionStore . listen ( this . _updateIndicators ) ;
2745 }
2846
2947 componentWillUnmount ( ) {
30- console . log ( 'componentWillUnmount' ) ;
3148 var parent = React . findDOMNode ( this ) ;
3249 parent . removeChild ( this . tx ) ;
3350 parent . removeChild ( this . rx ) ;
3451 this . tx = null ;
3552 this . rx = null ;
53+ transmissionStore . unlisten ( this . _updateIndicators ) ;
3654 }
3755
38- shouldComponentUpdate ( nextProps ) {
39- const { flashRx, flashTx } = this . props ;
40- if ( this . rx != null && nextProps . flashRx !== flashRx ) {
41- if ( nextProps . flashRx ) {
42- this . rx . style . backgroundColor = styles . rx . backgroundColor ;
43- } else {
44- this . rx . style . backgroundColor = styles . indicator . backgroundColor ;
45- }
46- }
47- if ( this . tx != null && nextProps . flashTx !== flashTx ) {
48- if ( nextProps . flashTx ) {
49- this . tx . style . backgroundColor = styles . tx . backgroundColor ;
50- } else {
51- this . tx . style . backgroundColor = styles . indicator . backgroundColor ;
52- }
53- }
56+ shouldComponentUpdate ( ) {
5457 return false ;
5558 }
5659
5760 render ( ) {
58- // const { flashRx, flashTx } = this.props;
59-
60- // let indicatorRx = [styles.indicator];
61- // let indicatorTx = [styles.indicator];
62- // if(flashRx) {
63- // indicatorRx.push(styles.rx);
64- // }
65- // if(flashTx) {
66- // indicatorTx.push(styles.tx);
67- // }
68- //TX<span styles={indicatorTx} /> RX<span styles={indicatorRx} />
6961 return (
70- < span style = { styles . rxtx } >
71- </ span >
62+ < span style = { styles . rxtx } > </ span >
7263 ) ;
7364 }
7465}
7566
76- module . exports = createContainer ( Indicators , {
77- getStores ( ) {
78- return {
79- deviceStore : transmissionStore
80- } ;
81- } ,
82-
83- getPropsFromStores ( ) {
84- return transmissionStore . getState ( ) ;
85- }
86- } ) ;
67+ module . exports = Indicators ;
0 commit comments