Skip to content

Commit 1dd4a8c

Browse files
feat(overmind): improve warning on development exp and new option to turn off proxy value logging
1 parent 193d246 commit 1dd4a8c

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,30 @@ export class Overmind<Config extends Configuration> implements Configuration {
113113
*/
114114

115115
if (!IS_PRODUCTION && typeof window !== 'undefined') {
116-
const originalConsoleLog = console.log
117-
console.log = (...args) =>
118-
originalConsoleLog.apply(
119-
console,
120-
args.map((arg) => (arg && arg[IS_PROXY] ? arg[VALUE] : arg))
121-
)
116+
let warning = 'OVERMIND: You are running in DEVELOPMENT mode.'
117+
if (options.logProxies !== true) {
118+
const originalConsoleLog = console.log
119+
120+
console.log = (...args) =>
121+
originalConsoleLog.apply(
122+
console,
123+
args.map((arg) => (arg && arg[IS_PROXY] ? arg[VALUE] : arg))
124+
)
125+
warning +=
126+
'\n\n - To improve debugging experience "console.log" will NOT log proxies from Overmind, but the actual value. Please see docs to turn off this behaviour'
127+
}
128+
122129
if (
123130
options.devtools ||
124131
(location.hostname === 'localhost' && options.devtools !== false)
125132
) {
126133
this.initializeDevtools(options.devtools, eventHub, proxyStateTree)
127134
} else {
128-
console.warn(
129-
'OVERMIND: You are running in development mode, but not on localhost. You will have to manually define the devtools option to connect'
130-
)
135+
warning +=
136+
'\n\n - You are not running on localhost. You will have to manually define the devtools option to connect'
131137
}
138+
139+
console.warn(warning)
132140
}
133141

134142
eventHub.on(EventType.OPERATOR_ASYNC, (data) => {

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type SubType<Base, Condition> = Pick<
99
export type Options = {
1010
name?: string
1111
devtools?: string | boolean
12+
logProxies?: boolean
1213
}
1314

1415
export enum EventType {

packages/overmind-website/api/overmind.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ By default the application connects to the devtools on **localhost:3031**, but y
2222

2323
```marksy
2424
h(Example, { name: "api/app_options_devtools" })
25+
```
26+
27+
## options.logProxies
28+
By default, in **development**, Overmind will make sure that any usage of **console.log** will log out the actual object/array, instead of any proxy wrapping it. This is most likely what you want. If you want to turn off this behaviour, set this option to **true**.
29+
30+
```marksy
31+
h(Example, { name: "api/app_options_logproxies" })
2532
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export default (ts) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'app/index.ts',
6+
code: `
7+
...
8+
9+
export const app = new Overmind(config, {
10+
logProxies: false
11+
})
12+
`,
13+
},
14+
]
15+
: [
16+
{
17+
fileName: 'app/index.js',
18+
code: `
19+
...
20+
21+
export const app = new Overmind(config, {
22+
logProxies: false
23+
})
24+
`,
25+
},
26+
]

0 commit comments

Comments
 (0)