Skip to content

Commit

Permalink
Make devtools error loglevel configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
geirsagberg committed Aug 1, 2021
1 parent a782b1d commit 8fd9c1f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/overmind/src/Devtools.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LogLevel } from './internalTypes'
import { SERIALIZE } from './rehydrate'

export type Message = {
Expand All @@ -23,7 +24,7 @@ export class Devtools {
private hasWarnedReconnect: boolean = false
private reconnectInterval: number = 10000
private name: string
constructor(name: string) {
constructor(name: string, private logLevel: LogLevel = 'error') {
this.name =
typeof location !== 'undefined' &&
location.search.includes('OVERMIND_DEVTOOL')
Expand All @@ -48,7 +49,7 @@ export class Devtools {
this.flushBuffer()
}
this.ws.onerror = () => {
console.error(
console[this.logLevel](
`OVERMIND DEVTOOLS: Not able to connect. You are trying to connect to "${host}", but there was no devtool there. Try the following:
- Make sure you are running the latest version of the devtools, using "npx overmind-devtools@latest" or install latest extension for VSCode
Expand Down
16 changes: 12 additions & 4 deletions packages/overmind/src/Overmind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Devtools, DevtoolsMessage } from './Devtools'
import * as internalTypes from './internalTypes'
import { proxifyEffects } from './proxyfyEffects'
import { rehydrate } from './rehydrate'
import { IConfiguration, IReaction, IContext } from './types'
import { IConfiguration, IContext, IReaction } from './types'
import * as utils from './utils'

const hotReloadingCache = {}
Expand Down Expand Up @@ -144,7 +144,8 @@ export class Overmind<ThisConfig extends IConfiguration>
name,
eventHub,
proxyStateTreeInstance.sourceState,
configuration.actions
configuration.actions,
options.devtoolsLogLevel
)
} else if (options.devtools !== false) {
warning +=
Expand Down Expand Up @@ -695,9 +696,16 @@ export class Overmind<ThisConfig extends IConfiguration>
})
}

private initializeDevtools(host, name, eventHub, initialState, actions) {
private initializeDevtools(
host,
name,
eventHub,
initialState,
actions,
logLevel: internalTypes.LogLevel
) {
if (utils.ENVIRONMENT === 'production') return
const devtools = new Devtools(name)
const devtools = new Devtools(name, logLevel)
devtools.connect(
host,
(message: DevtoolsMessage) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/overmind/src/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
IMutationTree,
ITrackStateTree,
} from 'proxy-state-tree'

import { IAction, IOperator } from './types'

export type SubType<Base, Condition> = Pick<
Expand All @@ -18,6 +17,8 @@ export type NestedPartial<T> = T extends Function
? T
: Partial<{ [P in keyof T]: NestedPartial<T[P]> }>

export type LogLevel = 'debug' | 'info' | 'warn' | 'error'

export type Options = {
delimiter?: string
name?: string
Expand All @@ -26,6 +27,7 @@ export type Options = {
logProxies?: boolean
hotReloading?: boolean
strict?: boolean
devtoolsLogLevel?: LogLevel
}

export type DefaultMode = {
Expand Down

0 comments on commit 8fd9c1f

Please sign in to comment.