File tree 2 files changed +14
-6
lines changed
2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -162,9 +162,13 @@ export function mergeMeta(meta: Record<string, any>) {
162
162
return acc ;
163
163
} , { } ) ;
164
164
}
165
- function getCircularReplacer ( ) {
165
+ function getCircularReplacer ( stripKeys : string [ ] ) {
166
166
const seen = new WeakSet ( ) ;
167
167
return ( key : string , value : any ) => {
168
+ if ( stripKeys . includes ( key ) ) {
169
+ return ;
170
+ }
171
+
168
172
if ( typeof value === "object" && value !== null ) {
169
173
if ( seen . has ( value ) ) {
170
174
// Circular reference found, discard key
@@ -177,6 +181,9 @@ function getCircularReplacer() {
177
181
} ;
178
182
}
179
183
180
- export function toJSON < T = unknown > ( value : unknown ) : T {
181
- return JSON . parse ( JSON . stringify ( value , getCircularReplacer ( ) ) ) ;
184
+ export function toJSON < T = unknown > (
185
+ value : unknown ,
186
+ stripKeys = [ ] as string [ ]
187
+ ) : T {
188
+ return JSON . parse ( JSON . stringify ( value , getCircularReplacer ( stripKeys ) ) ) ;
182
189
}
Original file line number Diff line number Diff line change @@ -352,17 +352,18 @@ export function buildRootComponent<TMachine extends AnyXstateTreeMachine>(
352
352
const lastSnapshot =
353
353
lastSnapshotsRef . current [ event . actorRef . sessionId ] ;
354
354
355
+ const strippedKeys = [ "_subscription" ] ;
355
356
if ( ! lastSnapshot ) {
356
357
console . log (
357
358
`[xstate-tree] initial snapshot: ${ event . actorRef . id } ` ,
358
- toJSON ( event . snapshot )
359
+ toJSON ( event . snapshot , strippedKeys )
359
360
) ;
360
361
} else {
361
362
console . log (
362
363
`[xstate-tree] snapshot: ${ event . actorRef . id } transitioning to` ,
363
- toJSON ( event . snapshot ) ,
364
+ toJSON ( event . snapshot , strippedKeys ) ,
364
365
"from" ,
365
- toJSON ( lastSnapshot )
366
+ toJSON ( lastSnapshot , strippedKeys )
366
367
) ;
367
368
}
368
369
You can’t perform that action at this time.
0 commit comments