Skip to content

Commit 04db26a

Browse files
authored
Update debugger from upstream (#240)
* Update debugger from upstream facebook/react-native@e5aa5b7 * Upgrade Expo / RN versions in examples * Fix lint error * Fix worker didnt post message if checkDeltaAvailable failed * Remove unnecessary waitingScriptExecuted
1 parent 9beee06 commit 04db26a

File tree

9 files changed

+3479
-2111
lines changed

9 files changed

+3479
-2111
lines changed

app/middlewares/debuggerAPI.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const currentWindow = remote.getCurrentWindow();
2323
const { SET_DEBUGGER_LOCATION, BEFORE_WINDOW_CLOSE } = debuggerActions;
2424

2525
let worker;
26+
let queuedMessages = [];
2627
let scriptExecuted = false;
2728
let actions;
2829
let host;
@@ -83,12 +84,11 @@ const clearLogs = () => {
8384
}
8485
};
8586

86-
const interval = time => new Promise(resolve => setTimeout(resolve, time));
87-
88-
const waitingScriptExecuted = async () => {
89-
while (!scriptExecuted) {
90-
await interval(50);
91-
}
87+
const flushQueuedMessages = () => {
88+
if (!worker) return;
89+
// Flush any messages queued up and clear them
90+
queuedMessages.forEach(message => worker.postMessage(message));
91+
queuedMessages = [];
9292
};
9393

9494
const connectToDebuggerProxy = async () => {
@@ -97,25 +97,14 @@ const connectToDebuggerProxy = async () => {
9797
const { setDebuggerStatus } = actions;
9898
ws.onopen = () => setDebuggerStatus('waiting');
9999
ws.onmessage = async message => {
100-
if (!message.data) {
101-
return;
102-
}
103-
const object = JSON.parse(message.data);
100+
if (!message.data) return;
104101

102+
const object = JSON.parse(message.data);
105103
if (object.$event === 'client-disconnected') {
106104
shutdownJSRuntime();
107105
return;
108106
}
109-
110-
if (!object.method) {
111-
return;
112-
}
113-
114-
// Check Delta support will be consume more delay time,
115-
// continuing messages may cause it to error (In case of RN 0.45),
116-
if (!scriptExecuted && object.method === 'callFunctionReturnFlushedQueue') {
117-
await waitingScriptExecuted();
118-
}
107+
if (!object.method) return;
119108

120109
// Special message that asks for a new JS runtime
121110
if (object.method === 'prepareJSRuntime') {
@@ -127,7 +116,6 @@ const connectToDebuggerProxy = async () => {
127116
} else if (object.method === '$disconnected') {
128117
shutdownJSRuntime();
129118
} else {
130-
// Otherwise, pass through to the worker.
131119
if (!worker) return;
132120
if (object.method === 'executeApplicationScript') {
133121
object.networkInspect = networkInspect.isEnabled();
@@ -143,6 +131,7 @@ const connectToDebuggerProxy = async () => {
143131
clearLogs();
144132
scriptExecuted = true;
145133
worker.postMessage({ ...object, url });
134+
flushQueuedMessages();
146135
return;
147136
}
148137
} finally {
@@ -151,7 +140,15 @@ const connectToDebuggerProxy = async () => {
151140
scriptExecuted = true;
152141
}
153142
}
154-
worker.postMessage(object);
143+
if (scriptExecuted) {
144+
// Otherwise, pass through to the worker provided the
145+
// application script has been executed. If not add
146+
// it to a queue until it has been executed.
147+
worker.postMessage(object);
148+
flushQueuedMessages();
149+
} else {
150+
queuedMessages.push(object);
151+
}
155152
}
156153
};
157154

examples/counter-with-mobx/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"expo": {
3-
"sdkVersion": "20.0.0"
3+
"sdkVersion": "27.0.0"
44
}
55
}

examples/counter-with-mobx/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6-
"jest-expo": "~20.0.0",
7-
"react-native-debugger-open": "^0.3.11",
8-
"react-native-scripts": "1.3.1",
9-
"react-test-renderer": "16.0.0-alpha.12"
6+
"jest-expo": "~27.0.0",
7+
"react-native-debugger-open": "^0.3.17",
8+
"react-native-scripts": "1.14.0",
9+
"react-test-renderer": "16.3.1"
1010
},
1111
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
1212
"scripts": {
@@ -21,11 +21,11 @@
2121
"preset": "jest-expo"
2222
},
2323
"dependencies": {
24-
"expo": "^20.0.0",
24+
"expo": "~27.0.0",
2525
"mobx": "^3.1.9",
2626
"mobx-react": "^4.1.8",
2727
"mobx-remotedev": "^0.2.6",
28-
"react": "16.0.0-alpha.12",
29-
"react-native": "^0.47.0"
28+
"react": "16.3.1",
29+
"react-native": "^0.55.4"
3030
}
3131
}

examples/counter-with-mobx/src/containers/Counter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import { StyleSheet, Text, View, TouchableHighlight } from 'react-native';
34
import { observer } from 'mobx-react/native';
45

examples/counter-with-redux/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"expo": {
3-
"sdkVersion": "20.0.0"
3+
"sdkVersion": "27.0.0"
44
}
55
}

examples/counter-with-redux/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"devDependencies": {
6-
"jest-expo": "~20.0.0",
7-
"react-native-debugger-open": "^0.3.11",
8-
"react-native-scripts": "1.3.1",
9-
"react-test-renderer": "16.0.0-alpha.12"
6+
"jest-expo": "^27.0.0",
7+
"react-native-debugger-open": "^0.3.17",
8+
"react-native-scripts": "1.14.0",
9+
"react-test-renderer": "16.3.1"
1010
},
1111
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
1212
"scripts": {
@@ -21,9 +21,10 @@
2121
"preset": "jest-expo"
2222
},
2323
"dependencies": {
24-
"expo": "^20.0.0",
25-
"react": "16.0.0-alpha.12",
26-
"react-native": "^0.47.0",
24+
"expo": "^27.0.0",
25+
"prop-types": "^15.6.1",
26+
"react": "16.3.1",
27+
"react-native": "^0.55.4",
2728
"react-redux": "^5.0.6",
2829
"redux": "^3.7.2",
2930
"redux-devtools-extension": "^2.13.2",

examples/counter-with-redux/src/configureStore.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import thunk from 'redux-thunk';
55
import reducer from './reducers';
66

77
const middlewares = [thunk];
8-
const enhancer = composeWithDevTools(
9-
{
10-
// Options: https://github.com/jhen0409/react-native-debugger#options
11-
},
12-
)(applyMiddleware(...middlewares));
8+
const enhancer = composeWithDevTools({
9+
// Options: https://github.com/jhen0409/react-native-debugger#options
10+
})(applyMiddleware(...middlewares));
1311

1412
export default function configureStore(initialState) {
1513
const store = createStore(reducer, initialState, enhancer);

examples/counter-with-redux/src/containers/Counter.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, { Component } from 'react';
2+
import PropTypes from 'prop-types';
23
import { StyleSheet, View, Text, TouchableHighlight } from 'react-native';
34

45
import { bindActionCreators } from 'redux';
@@ -19,7 +20,10 @@ const styles = StyleSheet.create({
1920
},
2021
});
2122

22-
@connect(state => state, dispatch => bindActionCreators(CounterActions, dispatch))
23+
@connect(
24+
state => state,
25+
dispatch => bindActionCreators(CounterActions, dispatch)
26+
)
2327
export default class Counter extends Component {
2428
static propTypes = {
2529
incrementAsync: PropTypes.func.isRequired,

0 commit comments

Comments
 (0)