forked from Wolox/wolmo-bootstrap-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreactotronConfig.ejs
More file actions
70 lines (61 loc) · 2.19 KB
/
reactotronConfig.ejs
File metadata and controls
70 lines (61 loc) · 2.19 KB
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
import Immutable from 'seamless-immutable';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Reactotron, { overlay, trackGlobalErrors } from 'reactotron-react-native';
import ReactotronFlipper from 'reactotron-react-native/dist/flipper';
import apisaucePlugin from 'reactotron-apisauce';
import { reactotronRedux } from 'reactotron-redux';
import { NativeModules } from 'react-native';
import { Tron } from '@interfaces/reactotron';
// Console augmentation
declare global {
interface Console {
tron: Tron;
}
}
// If you want to use a physical device and connect it to reactotron, execute first 'adb reverse tcp:9090 tcp:9090'
if (__DEV__) {
const { scriptURL } = NativeModules.SourceCode;
const scriptHostname = scriptURL.split('://')[1].split(':')[0];
Reactotron.configure({
name: '<%= projectName %>',
host: scriptHostname,
createSocket: path => new ReactotronFlipper(path)
})
.use(trackGlobalErrors({}))
.use(apisaucePlugin())
.use(
reactotronRedux({
onRestore: state =>
Object.entries(state).reduce(
(prev, [key, value]) => ({ ...prev, [key]: key === 'nav' ? value : Immutable(value) }),
{}
)
})
)
.use(overlay())
.setAsyncStorageHandler?.(AsyncStorage)
.connect();
// eslint-disable-next-line no-console
console.tron = {
log: Reactotron.logImportant,
clear: Reactotron.clear,
customCommand: Reactotron.onCustomCommand,
display: Reactotron.display
};
}
/* Here is an example of how to use customCommand
const selfRemoving = console.tron.customCommand({
command: "remove",
handler: () => {
selfRemoving() // Calling it unregisters the command
},
})
This will display a button in Reactotron which will execute the whole handler
block when clicked.
Is important to know that a customCommand can't be declared/registered twice
So we have to unregister it if we are going to run the same block again.
If you use this pattern the customCommand will be unregistered when executed
to avoid conflics in the future. A good way to register a customCommand is in the
ComponentDidMount life cycle method of the desired component
*/
export default Reactotron;