|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +const _ = require('lodash'); |
3 | 4 | const React = require('react'); |
| 5 | +const { createContainer } = require('sovereign'); |
4 | 6 |
|
5 | 7 | const styles = require('./styles'); |
| 8 | +const transmissionStore = require('../../src/stores/transmission'); |
6 | 9 |
|
7 | 10 | class Indicators extends React.Component { |
8 | 11 |
|
9 | | - render() { |
10 | | - const { flashRx, flashTx } = this.props; |
| 12 | + componentDidMount() { |
| 13 | + var parent = React.findDOMNode(this); |
| 14 | + var tx = this.tx = document.createElement('span'); |
| 15 | + var rx = this.rx = document.createElement('span'); |
| 16 | + this.txLabel = document.createTextNode('TX'); |
| 17 | + this.rxLabel = document.createTextNode(' RX'); |
| 18 | + parent.appendChild(this.txLabel); |
| 19 | + parent.appendChild(tx); |
| 20 | + parent.appendChild(this.rxLabel); |
| 21 | + parent.appendChild(rx); |
| 22 | + _.forEach(styles.indicator, function(style, name){ |
| 23 | + tx.style[name] = style; |
| 24 | + rx.style[name] = style; |
| 25 | + }); |
| 26 | + console.log('componentDidMount', tx, rx, tx.style); |
| 27 | + } |
11 | 28 |
|
12 | | - let indicatorRx = [styles.indicator]; |
13 | | - let indicatorTx = [styles.indicator]; |
14 | | - if(flashRx) { |
15 | | - indicatorRx.push(styles.rx); |
| 29 | + componentWillUnmount() { |
| 30 | + console.log('componentWillUnmount'); |
| 31 | + var parent = React.findDOMNode(this); |
| 32 | + parent.removeChild(this.tx); |
| 33 | + parent.removeChild(this.rx); |
| 34 | + this.tx = null; |
| 35 | + this.rx = null; |
| 36 | + } |
| 37 | + |
| 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 | + } |
16 | 46 | } |
17 | | - if(flashTx) { |
18 | | - indicatorTx.push(styles.tx); |
| 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 | + } |
19 | 53 | } |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + render() { |
| 58 | + // const { flashRx, flashTx } = this.props; |
20 | 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} /> |
21 | 69 | return ( |
22 | 70 | <span style={styles.rxtx}> |
23 | | - TX<span styles={indicatorTx} />RX<span styles={indicatorRx} /> |
24 | 71 | </span> |
25 | 72 | ); |
26 | 73 | } |
27 | 74 | } |
28 | 75 |
|
29 | | -module.exports = Indicators; |
| 76 | +module.exports = createContainer(Indicators, { |
| 77 | + getStores(){ |
| 78 | + return { |
| 79 | + deviceStore: transmissionStore |
| 80 | + }; |
| 81 | + }, |
| 82 | + |
| 83 | + getPropsFromStores() { |
| 84 | + return transmissionStore.getState(); |
| 85 | + } |
| 86 | +}); |
0 commit comments