Skip to content

Commit

Permalink
Update debugger from upstream (#240)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jhen0409 committed Jun 17, 2018
1 parent 9beee06 commit 04db26a
Show file tree
Hide file tree
Showing 9 changed files with 3,479 additions and 2,111 deletions.
41 changes: 19 additions & 22 deletions app/middlewares/debuggerAPI.js
Expand Up @@ -23,6 +23,7 @@ const currentWindow = remote.getCurrentWindow();
const { SET_DEBUGGER_LOCATION, BEFORE_WINDOW_CLOSE } = debuggerActions;

let worker;
let queuedMessages = [];
let scriptExecuted = false;
let actions;
let host;
Expand Down Expand Up @@ -83,12 +84,11 @@ const clearLogs = () => {
}
};

const interval = time => new Promise(resolve => setTimeout(resolve, time));

const waitingScriptExecuted = async () => {
while (!scriptExecuted) {
await interval(50);
}
const flushQueuedMessages = () => {
if (!worker) return;
// Flush any messages queued up and clear them
queuedMessages.forEach(message => worker.postMessage(message));
queuedMessages = [];
};

const connectToDebuggerProxy = async () => {
Expand All @@ -97,25 +97,14 @@ const connectToDebuggerProxy = async () => {
const { setDebuggerStatus } = actions;
ws.onopen = () => setDebuggerStatus('waiting');
ws.onmessage = async message => {
if (!message.data) {
return;
}
const object = JSON.parse(message.data);
if (!message.data) return;

const object = JSON.parse(message.data);
if (object.$event === 'client-disconnected') {
shutdownJSRuntime();
return;
}

if (!object.method) {
return;
}

// Check Delta support will be consume more delay time,
// continuing messages may cause it to error (In case of RN 0.45),
if (!scriptExecuted && object.method === 'callFunctionReturnFlushedQueue') {
await waitingScriptExecuted();
}
if (!object.method) return;

// Special message that asks for a new JS runtime
if (object.method === 'prepareJSRuntime') {
Expand All @@ -127,7 +116,6 @@ const connectToDebuggerProxy = async () => {
} else if (object.method === '$disconnected') {
shutdownJSRuntime();
} else {
// Otherwise, pass through to the worker.
if (!worker) return;
if (object.method === 'executeApplicationScript') {
object.networkInspect = networkInspect.isEnabled();
Expand All @@ -143,6 +131,7 @@ const connectToDebuggerProxy = async () => {
clearLogs();
scriptExecuted = true;
worker.postMessage({ ...object, url });
flushQueuedMessages();
return;
}
} finally {
Expand All @@ -151,7 +140,15 @@ const connectToDebuggerProxy = async () => {
scriptExecuted = true;
}
}
worker.postMessage(object);
if (scriptExecuted) {
// Otherwise, pass through to the worker provided the
// application script has been executed. If not add
// it to a queue until it has been executed.
worker.postMessage(object);
flushQueuedMessages();
} else {
queuedMessages.push(object);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion examples/counter-with-mobx/app.json
@@ -1,5 +1,5 @@
{
"expo": {
"sdkVersion": "20.0.0"
"sdkVersion": "27.0.0"
}
}
14 changes: 7 additions & 7 deletions examples/counter-with-mobx/package.json
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~20.0.0",
"react-native-debugger-open": "^0.3.11",
"react-native-scripts": "1.3.1",
"react-test-renderer": "16.0.0-alpha.12"
"jest-expo": "~27.0.0",
"react-native-debugger-open": "^0.3.17",
"react-native-scripts": "1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
Expand All @@ -21,11 +21,11 @@
"preset": "jest-expo"
},
"dependencies": {
"expo": "^20.0.0",
"expo": "~27.0.0",
"mobx": "^3.1.9",
"mobx-react": "^4.1.8",
"mobx-remotedev": "^0.2.6",
"react": "16.0.0-alpha.12",
"react-native": "^0.47.0"
"react": "16.3.1",
"react-native": "^0.55.4"
}
}
3 changes: 2 additions & 1 deletion examples/counter-with-mobx/src/containers/Counter.js
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, Text, View, TouchableHighlight } from 'react-native';
import { observer } from 'mobx-react/native';

Expand Down
2 changes: 1 addition & 1 deletion examples/counter-with-redux/app.json
@@ -1,5 +1,5 @@
{
"expo": {
"sdkVersion": "20.0.0"
"sdkVersion": "27.0.0"
}
}
15 changes: 8 additions & 7 deletions examples/counter-with-redux/package.json
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~20.0.0",
"react-native-debugger-open": "^0.3.11",
"react-native-scripts": "1.3.1",
"react-test-renderer": "16.0.0-alpha.12"
"jest-expo": "^27.0.0",
"react-native-debugger-open": "^0.3.17",
"react-native-scripts": "1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
Expand All @@ -21,9 +21,10 @@
"preset": "jest-expo"
},
"dependencies": {
"expo": "^20.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.47.0",
"expo": "^27.0.0",
"prop-types": "^15.6.1",
"react": "16.3.1",
"react-native": "^0.55.4",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-devtools-extension": "^2.13.2",
Expand Down
8 changes: 3 additions & 5 deletions examples/counter-with-redux/src/configureStore.js
Expand Up @@ -5,11 +5,9 @@ import thunk from 'redux-thunk';
import reducer from './reducers';

const middlewares = [thunk];
const enhancer = composeWithDevTools(
{
// Options: https://github.com/jhen0409/react-native-debugger#options
},
)(applyMiddleware(...middlewares));
const enhancer = composeWithDevTools({
// Options: https://github.com/jhen0409/react-native-debugger#options
})(applyMiddleware(...middlewares));

export default function configureStore(initialState) {
const store = createStore(reducer, initialState, enhancer);
Expand Down
8 changes: 6 additions & 2 deletions examples/counter-with-redux/src/containers/Counter.js
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { StyleSheet, View, Text, TouchableHighlight } from 'react-native';

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

@connect(state => state, dispatch => bindActionCreators(CounterActions, dispatch))
@connect(
state => state,
dispatch => bindActionCreators(CounterActions, dispatch)
)
export default class Counter extends Component {
static propTypes = {
incrementAsync: PropTypes.func.isRequired,
Expand Down

0 comments on commit 04db26a

Please sign in to comment.