@@ -7,6 +7,7 @@ import DiffViewer from "@/components/messages2/DiffViewer.vue";
77import CodeEditor from " @/components/CodeEditor.vue" ;
88import { useSagaDiagramStore } from " @/stores/SagaDiagramStore" ;
99import { ref , watch , computed } from " vue" ;
10+ import { parse , stringify } from " lossless-json" ;
1011
1112// Import the images directly
1213import CommandIcon from " @/assets/command.svg" ;
@@ -16,13 +17,6 @@ import TimeoutIcon from "@/assets/timeout.svg";
1617import EventIcon from " @/assets/event.svg" ;
1718import SagaTimeoutIcon from " @/assets/SagaTimeoutIcon.svg" ;
1819
19- // Define types for JSON values and properties
20- type JsonValue = string | number | boolean | null | JsonObject | JsonArray ;
21- interface JsonObject {
22- [key : string ]: JsonValue ;
23- }
24- type JsonArray = Array <JsonValue >;
25-
2620const props = defineProps <{
2721 update: SagaUpdateViewModel ;
2822 showMessageData? : boolean ;
@@ -57,18 +51,20 @@ watch(
5751const formatJsonValue = (value : unknown ): string => {
5852 if (value === null || value === undefined ) return " null" ;
5953 if (typeof value === " object" ) {
60- return JSON . stringify (value , null , 2 );
54+ return stringify (value as object , null , 2 ) || " {} " ;
6155 }
6256 return String (value );
6357};
6458
6559// Process JSON state and remove standard properties
66- const processState = (state : string | undefined ): Record < string , JsonValue > => {
60+ const processState = (state : string | undefined ): object => {
6761 if (! state ) return {};
6862
6963 let stateObj: Record <string , unknown >;
7064 try {
71- stateObj = JSON .parse (state );
65+ const parsedState = parse (state );
66+
67+ stateObj = parsedState as Record <string , unknown >;
7268 } catch (e ) {
7369 console .error (" Error parsing state:" , e );
7470 hasParsingError .value = true ;
@@ -83,7 +79,7 @@ const processState = (state: string | undefined): Record<string, JsonValue> => {
8379 }
8480 });
8581
86- return stateObj as Record < string , JsonValue > ;
82+ return stateObj ;
8783};
8884
8985const sagaUpdateStateChanges = computed (() => {
@@ -120,7 +116,7 @@ const hasStateChanges = computed(() => {
120116 const currentState = processState (props .update .stateAfterChange );
121117 const previousState = processState (props .update .previousStateAfterChange );
122118
123- return JSON . stringify (currentState ) !== JSON . stringify (previousState );
119+ return stringify (currentState ) !== stringify (previousState );
124120});
125121 </script >
126122
0 commit comments