@@ -58,7 +58,27 @@ export const SPECIAL_TOKENS = {
58
58
'NaN' : NAN
59
59
}
60
60
61
+ class EncodeCache {
62
+ constructor ( ) {
63
+ this . map = new Map ( )
64
+ }
65
+
66
+ cache ( data , factory ) {
67
+ const cached = this . map . get ( data )
68
+ if ( cached ) {
69
+ return cached
70
+ } else {
71
+ const result = factory ( data )
72
+ this . map . set ( data , result )
73
+ return result
74
+ }
75
+ }
76
+ }
77
+
78
+ let encodeCache
79
+
61
80
export function stringify ( data ) {
81
+ encodeCache = new EncodeCache ( )
62
82
return CircularJSON . stringify ( data , replacer )
63
83
}
64
84
@@ -78,13 +98,13 @@ function replacer (key) {
78
98
} else if ( val instanceof Date ) {
79
99
return `[native Date ${ val . toString ( ) } ]`
80
100
} else if ( isVuexStore ( val ) ) {
81
- return getCustomStoreDetails ( val )
101
+ return encodeCache . cache ( val , ( ) => getCustomStoreDetails ( val ) )
82
102
} else if ( isVueRouter ( val ) ) {
83
- return getCustomRouterDetails ( val )
103
+ return encodeCache . cache ( val , ( ) => getCustomRouterDetails ( val ) )
84
104
} else if ( val && val . _isVue ) {
85
- return getCustomInstanceDetails ( val )
105
+ return encodeCache . cache ( val , ( ) => getCustomInstanceDetails ( val ) )
86
106
} else if ( isComponentDefinition ( val ) ) {
87
- return getCustomComponentDefinitionDetails ( val )
107
+ return encodeCache . cache ( val , ( ) => getCustomComponentDefinitionDetails ( val ) )
88
108
} else {
89
109
const type = typeof val
90
110
if ( type === 'function' ) {
0 commit comments