Skip to content

Commit f687786

Browse files
authored
Merge pull request iamdustan#32 from iamdustan/react-reconciler
Upgrade the dependencies
2 parents 0452471 + 0235848 commit f687786

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+5870
-1941
lines changed

.babelrc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
{
22
"presets": [
3-
"react",
4-
"es2015"
3+
[
4+
"@babel/preset-env", {
5+
targets: {node: 'current'},
6+
},
7+
],
8+
"@babel/preset-react",
9+
"@babel/preset-flow",
510
],
611
"plugins": [
7-
"transform-class-properties"
12+
"@babel/plugin-proposal-class-properties"
813
],
914
"env": {
1015
"test": {
1116
"plugins": [
12-
"./scripts/babel/test-deps",
13-
"transform-react-jsx-source"
17+
"./scripts/babel/test-deps"
1418
]
1519
}
1620
}

.eslintrc.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
module.exports = {
22
parser: 'babel-eslint',
3-
'extends': './node_modules/fbjs-scripts/eslint/.eslintrc.js',
4-
plugins: [
5-
'react',
6-
],
7-
globals: {
8-
ReactComponent: true,
9-
React$Component: true,
10-
ReactClass: true,
11-
React$Element: true,
12-
},
3+
plugins: ['react'],
134
rules: {
145
'object-curly-spacing': [2, 'never'],
156
'react/jsx-uses-react': 2,

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
language: node_js
33
node_js:
4-
- 5
4+
- 8
55
cache:
66
directories:
77
- node_modules
@@ -17,7 +17,7 @@ before_install:
1717
echo "Only docs were updated, stopping build process."
1818
exit 0
1919
else
20-
npm install flow-bin@0.36
20+
npm install flow-bin@0.94
2121
fi
2222
script:
2323
- |
@@ -28,7 +28,7 @@ script:
2828
elif [ "$TEST_TYPE" = test ]; then
2929
npm test
3030
else
31-
./scripts/test $TEST_TYPE
31+
npm test -- $TEST_TYPE
3232
fi
3333
env:
3434
- CXX=g++-4.8 TEST_TYPE=test

examples/basic-hook/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Blinking LED.
3+
* This example blinks the Arduino Uno built-in LED on pin 13 every 1 second.
4+
*/
5+
6+
import * as React from 'react';
7+
import {getPort} from '../port';
8+
import ReactHardware from '../../src';
9+
10+
// thanks Dan. https://overreacted.io/making-setinterval-declarative-with-react-hooks/
11+
function useInterval(callback, delay) {
12+
const savedCallback = React.useRef();
13+
14+
// Remember the latest callback.
15+
React.useEffect(() => {
16+
savedCallback.current = callback;
17+
}, [callback]);
18+
19+
// Set up the interval.
20+
React.useEffect(() => {
21+
function tick() {
22+
savedCallback.current();
23+
}
24+
if (delay !== null) {
25+
let id = setInterval(tick, delay);
26+
return () => clearInterval(id);
27+
}
28+
}, [delay]);
29+
}
30+
31+
const FlashingLedHook = () => {
32+
const [value, setState] = React.useState(1);
33+
useInterval(() => setState(value === 0 ? 1 : 0), 1000);
34+
35+
return <pin pin={13} value={value} mode={'OUTPUT'} />;
36+
};
37+
38+
ReactHardware.render(<FlashingLedHook />, getPort(), inst => {
39+
console.log('Rendered <%s />', 'FlashingLedHook');
40+
});

examples/basic/index.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
* This example blinks the Arduino Uno built-in LED on pin 13 every 1 second.
44
*/
55

6-
import React, {Component} from 'react';
6+
import * as React from 'react';
77
import {getPort} from '../port';
88
import ReactHardware from '../../src';
99

10-
class FlashingLed extends Component {
11-
constructor(props, context) {
12-
super(props, context);
13-
14-
this.state = {value: 1};
15-
}
10+
class FlashingLed extends React.Component<{}, {value: number}> {
11+
state = {value: 1};
1612

1713
componentDidMount() {
1814
setInterval(() => {
@@ -23,20 +19,10 @@ class FlashingLed extends Component {
2319
}
2420

2521
render() {
26-
return (
27-
<pin
28-
pin={13}
29-
value={this.state.value}
30-
mode={'OUTPUT'}
31-
/>
32-
);
22+
return <pin pin={13} value={this.state.value} mode={'OUTPUT'} />;
3323
}
3424
}
3525

36-
ReactHardware.render(
37-
<FlashingLed />,
38-
getPort(),
39-
(inst) => {
40-
console.log('Rendered <%s />', FlashingLed.name);
41-
}
42-
);
26+
ReactHardware.render(<FlashingLed />, getPort(), inst => {
27+
console.log('Rendered <%s />', FlashingLed.name);
28+
});

examples/button/index.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ import {getPort} from '../port';
1818
import ReactHardware from '../../src';
1919

2020
type HardwareEvent = {
21-
value: number;
22-
type: string;
21+
value: number,
22+
type: string,
2323
};
2424

2525
type P = {
26-
pin: number;
27-
onChange: ?(event:HardwareEvent) => any;
28-
onDown: ?(event:HardwareEvent) => any;
29-
onUp: ?(event:HardwareEvent) => any;
30-
}
26+
pin: number,
27+
onChange: ?(event: HardwareEvent) => any,
28+
onDown: ?(event: HardwareEvent) => any,
29+
onUp: ?(event: HardwareEvent) => any,
30+
};
3131

3232
class Button extends Component {
3333
props: P;
3434
defaultProps: {};
35-
onRead: (value:number) => any;
35+
onRead: (value: number) => any;
3636

37-
constructor(props:P, context:{}) {
37+
constructor(props: P, context: {}) {
3838
super(props, context);
3939

4040
this.onRead = this.onRead.bind(this);
4141
}
4242

43-
onRead(value:number) {
43+
onRead(value: number) {
4444
const {onDown, onUp, onChange} = this.props;
4545
if (value === 1 && typeof onDown === 'function') {
4646
onDown({value, type: 'down'});
@@ -54,13 +54,7 @@ class Button extends Component {
5454
}
5555

5656
render() {
57-
return (
58-
<pin
59-
pin={this.props.pin}
60-
onRead={this.onRead}
61-
mode={'INPUT'}
62-
/>
63-
);
57+
return <pin pin={this.props.pin} onRead={this.onRead} mode={'INPUT'} />;
6458
}
6559
}
6660

@@ -71,7 +65,7 @@ class App extends Component {
7165
super();
7266

7367
this.state = {on: false};
74-
this.toggle = (event:HardwareEvent) => {
68+
this.toggle = (event: HardwareEvent) => {
7569
this.setState({on: !this.state.on});
7670
};
7771
}
@@ -87,10 +81,6 @@ class App extends Component {
8781
}
8882
}
8983

90-
ReactHardware.render(
91-
<App />,
92-
getPort(),
93-
(inst) => {
94-
console.log('Rendered <ButtonApplication />');
95-
}
96-
);
84+
ReactHardware.render(<App />, getPort(), inst => {
85+
console.log('Rendered <ButtonApplication />');
86+
});

examples/change-child/index.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,7 @@ class PulsingLed extends Component {
3636
}
3737

3838
render() {
39-
return (
40-
<pin
41-
pin={this.props.pin}
42-
value={this.state.value}
43-
mode={'PWM'}
44-
/>
45-
);
39+
return <pin pin={this.props.pin} value={this.state.value} mode={'PWM'} />;
4640
}
4741
}
4842

@@ -69,11 +63,7 @@ class FlashingLed extends Component {
6963

7064
render() {
7165
return (
72-
<pin
73-
pin={this.props.pin}
74-
value={this.state.value}
75-
mode={'OUTPUT'}
76-
/>
66+
<pin pin={this.props.pin} value={this.state.value} mode={'OUTPUT'} />
7767
);
7868
}
7969
}
@@ -87,7 +77,10 @@ class Application extends React.Component {
8777
}
8878

8979
componentDidMount() {
90-
this.interval = setInterval(_ => this.setState({swapped: !this.state.swapped}), 4000);
80+
this.interval = setInterval(
81+
_ => this.setState({swapped: !this.state.swapped}),
82+
4000,
83+
);
9184
}
9285
componentWillUnmount() {
9386
clearInterval(this.interval);
@@ -103,11 +96,6 @@ class Application extends React.Component {
10396
}
10497
}
10598

106-
107-
ReactHardware.render(
108-
<Application />,
109-
getPort(),
110-
inst => {
111-
console.log('Rendered ChangingComponentApplication');
112-
}
113-
);
99+
ReactHardware.render(<Application />, getPort(), inst => {
100+
console.log('Rendered ChangingComponentApplication');
101+
});

examples/devtools/index.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ class FlashingLed extends Component {
4040

4141
render() {
4242
return (
43-
<pin
44-
pin={this.props.pin}
45-
value={this.state.value}
46-
mode={'OUTPUT'}
47-
/>
43+
<pin pin={this.props.pin} value={this.state.value} mode={'OUTPUT'} />
4844
);
4945
}
5046
}
@@ -74,13 +70,7 @@ class PulsingLed extends Component {
7470
}
7571

7672
render() {
77-
return (
78-
<pin
79-
pin={this.props.pin}
80-
value={this.state.value}
81-
mode={'PWM'}
82-
/>
83-
);
73+
return <pin pin={this.props.pin} value={this.state.value} mode={'PWM'} />;
8474
}
8575
}
8676

@@ -91,10 +81,6 @@ const Application = () => [
9181
<FlashingLed pin={12} delay={1000} />,
9282
];
9383

94-
ReactHardware.render(
95-
<Application />,
96-
getPort(),
97-
(inst) => {
98-
console.log('Rendered <%s />', 'Devtools demonstration');
99-
}
100-
);
84+
ReactHardware.render(<Application />, getPort(), inst => {
85+
console.log('Rendered <%s />', 'Devtools demonstration');
86+
});

examples/jeoparty/index.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ class JeopartyLed extends Component {
3939
}
4040

4141
render() {
42-
return (
43-
<led
44-
{...this.props}
45-
{...this.state}
46-
/>
47-
);
42+
return <led {...this.props} {...this.state} />;
4843
}
4944
}
5045

@@ -67,12 +62,12 @@ class Jeoparty extends Component {
6762

6863
componentDidMount() {
6964
// on a socket connection
70-
io.sockets.on('connection', (socket) => {
65+
io.sockets.on('connection', socket => {
7166
// Player Button LEDs
7267
// strobe
7368
socket.on('led-strobe-1', () => this.setState({led1: 'strobe'}));
7469
socket.on('led-strobe-2', () => this.setState({led2: 'strobe'}));
75-
socket.on('led-strobe-3', () => this.setState({led3: 'strobe'}));
70+
socket.on('led-strobe-3', () => this.setState({led3: 'strobe'}));
7671

7772
// on
7873
socket.on('led-on-all', () => {
@@ -92,7 +87,6 @@ class Jeoparty extends Component {
9287
socket.on('led-off-2', () => this.setState({led2: 'off'}));
9388
socket.on('led-off-3', () => this.setState({led3: 'off'}));
9489

95-
9690
// All LED Strobe
9791
socket.on('led-strobe-all', () => {
9892
this.setState({led1: 'strobe'});
@@ -104,7 +98,6 @@ class Jeoparty extends Component {
10498
}, 140);
10599
});
106100

107-
108101
// LED off
109102
socket.on('led-stop', () => {
110103
this.setState({
@@ -131,10 +124,6 @@ class Jeoparty extends Component {
131124
}
132125
}
133126

134-
ReactHardware.render(
135-
<Jeoparty />,
136-
getPort(),
137-
(inst) => {
138-
console.log('Rendered <Jeoparty />');
139-
}
140-
);
127+
ReactHardware.render(<Jeoparty />, getPort(), inst => {
128+
console.log('Rendered <Jeoparty />');
129+
});

0 commit comments

Comments
 (0)