Skip to content

Commit 184f2a5

Browse files
fix(overmind): make mutation values stringify safe
1 parent ccb2dac commit 184f2a5

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

packages/node_modules/overmind-devtools/src/app/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const state: State = {
4242
newPortValue: '',
4343
currentTab: Tab.State,
4444
expandedStatePaths: [''],
45-
expandAllActionDetails: false,
45+
expandAllActionDetails: true,
4646
expandedComponents: [],
4747
currentApp: (state) => state.apps[state.currentAppName],
4848
componentsMounted: (state) =>

packages/node_modules/overmind-devtools/src/components/ActionOperator/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const ActionOperator: SFC<Props> = ({
2525
const { state, actions } = useOvermind()
2626
const isExpanded = state.expandAllActionDetails || !operator.isCollapsed
2727

28-
console.log(operator.mutations)
2928
return (
3029
<div>
3130
{value === undefined ? null : (

packages/node_modules/overmind/src/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventEmitter } from 'betsy'
2-
import { IS_PROXY, ProxyStateTree, TTree } from 'proxy-state-tree'
2+
import { IS_PROXY, ProxyStateTree, TTree, IMutation } from 'proxy-state-tree'
33
import { Derived } from './derived'
4-
import { Devtools, Message, safeValue } from './Devtools'
4+
import { Devtools, Message, safeValue, safeValues } from './Devtools'
55
import {
66
Events,
77
EventType,
@@ -46,8 +46,12 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production'
4646
const IS_DEVELOPMENT = process.env.NODE_ENV === 'development'
4747
const IS_OPERATOR = Symbol('operator')
4848

49-
export const log = (...objects: any[]) =>
50-
console.log(...objects.map((obj) => JSON.parse(JSON.stringify(obj))))
49+
export const makeStringifySafeMutations = (mutations: IMutation[]) => {
50+
return mutations.map((mutation) => ({
51+
...mutation,
52+
args: safeValues(mutation.args),
53+
}))
54+
}
5155

5256
const hotReloadingCache = {}
5357

@@ -123,6 +127,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
123127
data: {
124128
...data,
125129
...flushData,
130+
mutations: makeStringifySafeMutations(flushData.mutations),
126131
},
127132
})
128133
}
@@ -135,6 +140,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
135140
data: {
136141
...data,
137142
...flushData,
143+
mutations: makeStringifySafeMutations(flushData.mutations),
138144
},
139145
})
140146
}
@@ -247,7 +253,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
247253
mutationTree.onMutation((mutation) => {
248254
this.eventHub.emit(EventType.MUTATIONS, {
249255
...execution,
250-
mutations: [mutation],
256+
mutations: makeStringifySafeMutations([mutation]),
251257
})
252258
setTimeout(() => {
253259
const flushData = this.proxyStateTree.flush(true)
@@ -257,6 +263,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
257263
data: {
258264
...execution,
259265
...flushData,
266+
mutations: makeStringifySafeMutations(flushData.mutations),
260267
},
261268
})
262269
}
@@ -749,7 +756,7 @@ export function mutate<Input, Config extends Configuration = TheConfig>(
749756
context.execution.emit(EventType.MUTATIONS, {
750757
...context.execution,
751758
operatorId: context.execution.operatorId + 1,
752-
mutations: [mutation],
759+
mutations: makeStringifySafeMutations([mutation]),
753760
})
754761
})
755762
}

0 commit comments

Comments
 (0)