-
Notifications
You must be signed in to change notification settings - Fork 29
/
remote-redux-devtools+0.5.16.patch
122 lines (113 loc) · 4.52 KB
/
remote-redux-devtools+0.5.16.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff --git a/node_modules/remote-redux-devtools/src/devTools.js b/node_modules/remote-redux-devtools/src/devTools.js
index 09001b2..3494dcb 100644
--- a/node_modules/remote-redux-devtools/src/devTools.js
+++ b/node_modules/remote-redux-devtools/src/devTools.js
@@ -1,8 +1,7 @@
-import { stringify, parse } from 'jsan';
+import { stringify } from 'jsan';
import socketCluster from 'socketcluster-client';
import configureStore from './configureStore';
import { defaultSocketOptions } from './constants';
-import getHostForRN from 'rn-host-detect';
import { evalAction, getActionsArray } from 'redux-devtools-core/lib/utils';
import catchErrors from 'redux-devtools-core/lib/utils/catchErrors';
import {
@@ -11,6 +10,7 @@ import {
filterStagedActions,
filterState
} from 'redux-devtools-core/lib/utils/filters';
+import importState from 'redux-devtools-core/lib/utils/importState';
function async(fn) {
setTimeout(fn, 0);
@@ -25,6 +25,10 @@ function getRandomId() {
}
class DevToolsEnhancer {
+ errorCounts = {};
+
+ // a function that returns a proper remote server hostname and uses
+ // `isEmulator` from 'react-native-device-info' is expected
constructor() {
this.enhance.updateStore = newStore => {
console.warn('devTools.updateStore is deprecated use composeWithDevTools instead: ' +
@@ -95,13 +99,33 @@ class DevToolsEnhancer {
}
}
+ importPayloadFrom = (state) => {
+ const instance = {
+ name: this.instanceName,
+ id: this.appInstanceId,
+ store: this.store,
+ };
+ try {
+ const nextLiftedState = importState(state, instance);
+ if (!nextLiftedState) {
+ return;
+ }
+ this.store.liftedStore.dispatch({ type: 'IMPORT_STATE', ...nextLiftedState });
+ this.relay(
+ 'STATE',
+ this.getLiftedState(),
+ instance
+ );
+ } catch (e) {
+ this.relay('ERROR', e.message, instance);
+ }
+ };
+
handleMessages = (message) => {
if (
message.type === 'IMPORT' || message.type === 'SYNC' && this.socket.id && message.id !== this.socket.id
) {
- this.store.liftedStore.dispatch({
- type: 'IMPORT_STATE', nextLiftedState: parse(message.state)
- });
+ this.importPayloadFrom(message.state);
} else if (message.type === 'UPDATE') {
this.relay('STATE', this.getLiftedState());
} else if (message.type === 'START') {
@@ -187,12 +211,19 @@ class DevToolsEnhancer {
}
};
+ startWrapper = () => {
+ if (this.started || (this.socket && this.socket.getState() === this.socket.CONNECTING)) {
+ return;
+ }
+ this.start();
+ };
+
start = () => {
if (this.started || this.socket && this.socket.getState() === this.socket.CONNECTING) return;
this.socket = socketCluster.connect(this.socketOptions);
- this.socket.on('error', function (err) {
+ this.socket.on('error', (err) => {
// if we've already had this error before, increment it's counter, otherwise assign it '1' since we've had the error once.
this.errorCounts[err.name] = this.errorCounts.hasOwnProperty(err.name) ? this.errorCounts[err.name] + 1 : 1;
@@ -229,7 +260,7 @@ class DevToolsEnhancer {
this.lastAction = action.type;
if (!this.started && this.sendOnError === 2 && this.store.liftedStore) async(this.checkForReducerErrors);
else if (action.action) {
- if (this.startOn && !this.started && this.startOn.indexOf(action.action.type) !== -1) async(this.start);
+ if (this.startOn && !this.started && this.startOn.indexOf(action.action.type) !== -1) async(this.startWrapper);
else if (this.stopOn && this.started && this.stopOn.indexOf(action.action.type) !== -1) async(this.stop);
else if (this.sendOn && !this.started && this.sendOn.indexOf(action.action.type) !== -1) async(this.send);
}
@@ -261,10 +292,7 @@ class DevToolsEnhancer {
}
enhance = (options = {}) => {
- this.init({
- ...options,
- hostname: getHostForRN(options.hostname || 'localhost')
- });
+ this.init(options);
const realtime = typeof options.realtime === 'undefined'
? process.env.NODE_ENV === 'development' : options.realtime;
if (!realtime && !(this.startOn || this.sendOn || this.sendOnError)) return f => f;
@@ -285,7 +313,8 @@ class DevToolsEnhancer {
}
)(reducer, initialState);
- if (realtime) this.start();
+ if (realtime) this.startWrapper();
+
this.store.subscribe(() => {
if (this.isMonitored) this.handleChange(this.store.getState(), this.getLiftedStateRaw(), maxAge);
});