Skip to content

Commit 350d089

Browse files
committed
Implement tx/rx flash with manual dom elements
1 parent 185a2d7 commit 350d089

File tree

3 files changed

+75
-28
lines changed

3 files changed

+75
-28
lines changed

plugins/editor/indicators.js

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,86 @@
11
'use strict';
22

3+
const _ = require('lodash');
34
const React = require('react');
5+
const { createContainer } = require('sovereign');
46

57
const styles = require('./styles');
8+
const transmissionStore = require('../../src/stores/transmission');
69

710
class Indicators extends React.Component {
811

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+
}
1128

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+
}
1646
}
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+
}
1953
}
54+
return false;
55+
}
56+
57+
render() {
58+
// const { flashRx, flashTx } = this.props;
2059

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} />
2169
return (
2270
<span style={styles.rxtx}>
23-
TX<span styles={indicatorTx} />RX<span styles={indicatorRx} />
2471
</span>
2572
);
2673
}
2774
}
2875

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+
});

plugins/editor/styles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const styles = {
2020
},
2121
indicator: {
2222
backgroundColor: grey,
23-
height: 10,
24-
width: 10,
23+
height: '10px',
24+
width: '10px',
2525
borderRadius: '100%',
2626
margin: '0px 10px',
2727
display: 'inline-block'

plugins/editor/transmission-bar.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
'use strict';
22

33
const React = require('react');
4-
const { createContainer } = require('sovereign');
54

65
const Indicators = require('./indicators');
76
const styles = require('./styles');
8-
const transmissionStore = require('../../src/stores/transmission');
97

108
class TransmissionBar extends React.Component {
119

12-
render() {
13-
const { flashRx, flashTx } = this.props;
10+
shouldComponentUpdate() {
11+
return false;
12+
}
1413

14+
render() {
1515
return (
1616
<div style={styles.bar}>
17-
<Indicators flashRx={flashRx} flashTx={flashTx} />
17+
<Indicators />
1818
</div>
1919
);
2020
}
2121
}
2222

23-
module.exports = createContainer(TransmissionBar, {
24-
getStores(){
25-
return {
26-
deviceStore: transmissionStore
27-
};
28-
},
29-
30-
getPropsFromStores() {
31-
return transmissionStore.getState();
32-
}
33-
});
23+
module.exports = TransmissionBar;

0 commit comments

Comments
 (0)