11import { EventEmitter } from 'betsy'
2- import { IS_PROXY , ProxyStateTree , TTree } from 'proxy-state-tree'
2+ import * as isPlainObject from 'is-plain-obj'
3+ import { IS_PROXY , ProxyStateTree , TTree , IMutation } from 'proxy-state-tree'
34import { Derived } from './derived'
4- import { Devtools , Message , safeValue } from './Devtools'
5+ import { Devtools , Message , safeValue , safeValues } from './Devtools'
56import {
67 Events ,
78 EventType ,
@@ -41,13 +42,16 @@ export type Derive<Parent extends TStateObject, Value> = TDerive<
4142
4243export type OnInitialize = TOnInitialize < TheConfig >
4344
44- const isPlainObject = require ( 'is-plain-object' )
4545const IS_PRODUCTION = process . env . NODE_ENV === 'production'
4646const IS_DEVELOPMENT = process . env . NODE_ENV === 'development'
4747const 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
5256const 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