-
Notifications
You must be signed in to change notification settings - Fork 968
Expand file tree
/
Copy pathReactotronConfig.ts
More file actions
174 lines (159 loc) · 4.97 KB
/
ReactotronConfig.ts
File metadata and controls
174 lines (159 loc) · 4.97 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* This file does the setup for integration with Reactotron, which is a
* free desktop app for inspecting and debugging your React Native app.
* @see https://github.com/infinitered/reactotron
*/
import { Platform, TurboModuleRegistry } from "react-native"
import AsyncStorage from "@react-native-async-storage/async-storage"
import { ArgType } from "reactotron-core-client"
import { mst } from "reactotron-mst"
import apisaucePlugin from "reactotron-apisauce"
import { reactotronRedux } from "reactotron-redux"
import apolloPlugin from "reactotron-apollo-client"
import { clear } from "app/utils/storage"
import { goBack, resetRoot, navigate } from "app/navigators/navigationUtilities"
import { Reactotron } from "./ReactotronClient"
import { client } from "../stores/apollo" // <--- update this location
const reactotron = Reactotron.configure({
name: require("../../package.json").name,
onConnect: () => {
/** since this file gets hot reloaded, let's clear the past logs every time we connect */
Reactotron.clear()
},
})
.use(apisaucePlugin({ ignoreContentTypes: /^(image)\/.*$/i }))
.use(reactotronRedux())
.use(
mst({
/** ignore some chatty `mobx-state-tree` actions */
filter: (event) => /postProcessSnapshot|@APPLY_SNAPSHOT/.test(event.name) === false,
})
)
.use(apolloPlugin({ apolloClient: client }))
if (Platform.OS !== "web") {
reactotron.setAsyncStorageHandler?.(AsyncStorage)
reactotron.useReactNative({
networking: {
ignoreUrls: /(logs|symbolicate)$/,
},
overlay: true,
})
}
/**
* Reactotron allows you to define custom commands that you can run
* from Reactotron itself, and they will run in your app.
*
* Define them in the section below with `onCustomCommand`. Use your
* creativity -- this is great for development to quickly and easily
* get your app into the state you want.
*
* NOTE: If you edit this file while running the app, you will need to do a full refresh
* or else your custom commands won't be registered correctly.
*/
/**
* This Platform.OS iOS restriction can be lifted in React Native 0.77
* The `DevMenu` module was missing in Android for the New Architecture
* See this PR for more details: https://github.com/facebook/react-native/pull/46723
*/
if (Platform.OS === "ios") {
reactotron.onCustomCommand({
title: "Show Dev Menu",
description: "Opens the React Native dev menu",
command: "showDevMenu",
handler: () => {
Reactotron.log("Showing React Native dev menu")
TurboModuleRegistry.get<{ show: () => void; getConstants: () => {} }>("DevMenu")?.show()
},
})
}
reactotron.onCustomCommand({
title: "Reset Root Store",
description: "Resets the MST store",
command: "resetStore",
handler: () => {
Reactotron.log("resetting store")
clear()
},
})
reactotron.onCustomCommand({
title: "Reset Navigation State",
description: "Resets the navigation state",
command: "resetNavigation",
handler: () => {
Reactotron.log("resetting navigation state")
resetRoot({ index: 0, routes: [] })
},
})
reactotron.onCustomCommand<[{ name: "route"; type: ArgType.String }]>({
command: "navigateTo",
handler: (args) => {
const { route } = args ?? {}
if (route) {
Reactotron.log(`Navigating to: ${route}`)
navigate(route as any) // this should be tied to the navigator, but since this is for debugging, we can navigate to illegal routes
} else {
Reactotron.log("Could not navigate. No route provided.")
}
},
title: "Navigate To Screen",
description: "Navigates to a screen by name.",
args: [{ name: "route", type: ArgType.String }],
})
reactotron.onCustomCommand({
title: "Go Back",
description: "Goes back",
command: "goBack",
handler: () => {
Reactotron.log("Going back")
goBack()
},
})
/**
* We're going to add `console.tron` to the Reactotron object.
* Now, anywhere in our app in development, we can use Reactotron like so:
*
* ```
* if (__DEV__) {
* console.tron.display({
* name: 'JOKE',
* preview: 'What's the best thing about Switzerland?',
* value: 'I don't know, but the flag is a big plus!',
* important: true
* })
* }
* ```
*
* Use this power responsibly! :)
*/
console.tron = reactotron
/**
* We tell typescript about our dark magic
*
* You can also import Reactotron yourself from ./reactotronClient
* and use it directly, like Reactotron.log('hello world')
*/
declare global {
interface Console {
/**
* Reactotron client for logging, displaying, measuring performance, and more.
* @see https://github.com/infinitered/reactotron
*
* @example
* if (__DEV__) {
* console.tron.display({
* name: 'JOKE',
* preview: 'What's the best thing about Switzerland?',
* value: 'I don't know, but the flag is a big plus!',
* important: true
* })
* }
*
*/
tron: typeof reactotron
}
}
/**
* Now that we've setup all our Reactotron configuration, let's connect!
*/
reactotron.connect()
export default reactotron