File tree Expand file tree Collapse file tree 1 file changed +30
-7
lines changed
packages/node_modules/overmind/src Expand file tree Collapse file tree 1 file changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,16 @@ export type DevtoolsMessage = {
1111 data : any
1212}
1313
14+ function isClass ( value : any ) {
15+ return (
16+ typeof value === 'object' &&
17+ ! Array . isArray ( value ) &&
18+ value !== null &&
19+ value . constructor &&
20+ value . constructor . name !== 'Object'
21+ )
22+ }
23+
1424export class Devtools {
1525 private safeClassNames : Set < string > = new Set ( )
1626 private unsafeClassNames : Set < string > = new Set ( )
@@ -90,13 +100,26 @@ export class Devtools {
90100 }
91101 }
92102
93- if (
94- typeof value === 'object' &&
95- value !== null &&
96- ! Array . isArray ( value ) &&
97- value . constructor &&
98- value . constructor . name !== 'Object'
99- ) {
103+ if ( Array . isArray ( value ) && isClass ( value [ 0 ] ) ) {
104+ if ( ! safeClassNames . has ( value [ 0 ] . constructor . name ) && ! unsafeClassNames . has ( value [ 0 ] . constructor . name ) ) {
105+ try {
106+ JSON . stringify ( value [ 0 ] )
107+ safeClassNames . add ( value [ 0 ] . constructor . name )
108+ } catch {
109+ unsafeClassNames . add ( value [ 0 ] . constructor . name )
110+ }
111+ }
112+
113+ if ( safeClassNames . has ( value [ 0 ] . constructor . name ) ) {
114+ return value . map ( ( item ) => ( {
115+ __CLASS__ : true ,
116+ name : value [ 0 ] . constructor . name ,
117+ value : item
118+ } ) )
119+ } else {
120+ return value . map ( ( ) => `[${ value . constructor . name || 'NOT SERIALIZABLE' } ]` )
121+ }
122+ } else if ( isClass ( value ) ) {
100123 if ( ! safeClassNames . has ( value . constructor . name ) && ! unsafeClassNames . has ( value . constructor . name ) ) {
101124 try {
102125 JSON . stringify ( value )
You can’t perform that action at this time.
0 commit comments