File tree 1 file changed +11
-5
lines changed
packages/pinia/src/devtools
1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -47,10 +47,7 @@ export async function actionGlobalCopyState(pinia: Pinia) {
47
47
export async function actionGlobalPasteState ( pinia : Pinia ) {
48
48
if ( checkClipboardAccess ( ) ) return
49
49
try {
50
- Object . assign (
51
- pinia . state . value ,
52
- JSON . parse ( await navigator . clipboard . readText ( ) )
53
- )
50
+ loadStoresState ( pinia , JSON . parse ( await navigator . clipboard . readText ( ) ) )
54
51
toastMessage ( 'Global state pasted from clipboard.' )
55
52
} catch ( error ) {
56
53
if ( checkNotFocusedError ( error ) ) return
@@ -111,7 +108,7 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
111
108
const result = await open ( )
112
109
if ( ! result ) return
113
110
const { text, file } = result
114
- Object . assign ( pinia . state . value , JSON . parse ( text ) )
111
+ loadStoresState ( pinia , JSON . parse ( text ) )
115
112
toastMessage ( `Global state imported from "${ file . name } ".` )
116
113
} catch ( error ) {
117
114
toastMessage (
@@ -121,3 +118,12 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
121
118
console . error ( error )
122
119
}
123
120
}
121
+
122
+ function loadStoresState ( pinia : Pinia , state : Record < string , unknown > ) {
123
+ for ( const key in state ) {
124
+ const storeState = pinia . state . value [ key ]
125
+ if ( storeState ) {
126
+ Object . assign ( storeState , state [ key ] )
127
+ }
128
+ }
129
+ }
You can’t perform that action at this time.
0 commit comments