@@ -7,6 +7,7 @@ import DiffViewer from "@/components/messages2/DiffViewer.vue";
7
7
import CodeEditor from " @/components/CodeEditor.vue" ;
8
8
import { useSagaDiagramStore } from " @/stores/SagaDiagramStore" ;
9
9
import { ref , watch , computed } from " vue" ;
10
+ import { parse , stringify } from " lossless-json" ;
10
11
11
12
// Import the images directly
12
13
import CommandIcon from " @/assets/command.svg" ;
@@ -16,13 +17,6 @@ import TimeoutIcon from "@/assets/timeout.svg";
16
17
import EventIcon from " @/assets/event.svg" ;
17
18
import SagaTimeoutIcon from " @/assets/SagaTimeoutIcon.svg" ;
18
19
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
-
26
20
const props = defineProps <{
27
21
update: SagaUpdateViewModel ;
28
22
showMessageData? : boolean ;
@@ -57,18 +51,20 @@ watch(
57
51
const formatJsonValue = (value : unknown ): string => {
58
52
if (value === null || value === undefined ) return " null" ;
59
53
if (typeof value === " object" ) {
60
- return JSON . stringify (value , null , 2 );
54
+ return stringify (value as object , null , 2 ) || " {} " ;
61
55
}
62
56
return String (value );
63
57
};
64
58
65
59
// Process JSON state and remove standard properties
66
- const processState = (state : string | undefined ): Record < string , JsonValue > => {
60
+ const processState = (state : string | undefined ): object => {
67
61
if (! state ) return {};
68
62
69
63
let stateObj: Record <string , unknown >;
70
64
try {
71
- stateObj = JSON .parse (state );
65
+ const parsedState = parse (state );
66
+
67
+ stateObj = parsedState as Record <string , unknown >;
72
68
} catch (e ) {
73
69
console .error (" Error parsing state:" , e );
74
70
hasParsingError .value = true ;
@@ -83,7 +79,7 @@ const processState = (state: string | undefined): Record<string, JsonValue> => {
83
79
}
84
80
});
85
81
86
- return stateObj as Record < string , JsonValue > ;
82
+ return stateObj ;
87
83
};
88
84
89
85
const sagaUpdateStateChanges = computed (() => {
@@ -120,7 +116,7 @@ const hasStateChanges = computed(() => {
120
116
const currentState = processState (props .update .stateAfterChange );
121
117
const previousState = processState (props .update .previousStateAfterChange );
122
118
123
- return JSON . stringify (currentState ) !== JSON . stringify (previousState );
119
+ return stringify (currentState ) !== stringify (previousState );
124
120
});
125
121
</script >
126
122
0 commit comments