File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
packages/pinia/src/devtools Expand file tree Collapse file tree 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) {
4747export async function actionGlobalPasteState ( pinia : Pinia ) {
4848 if ( checkClipboardAccess ( ) ) return
4949 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 ( ) ) )
5451 toastMessage ( 'Global state pasted from clipboard.' )
5552 } catch ( error ) {
5653 if ( checkNotFocusedError ( error ) ) return
@@ -111,7 +108,7 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
111108 const result = await open ( )
112109 if ( ! result ) return
113110 const { text, file } = result
114- Object . assign ( pinia . state . value , JSON . parse ( text ) )
111+ loadStoresState ( pinia , JSON . parse ( text ) )
115112 toastMessage ( `Global state imported from "${ file . name } ".` )
116113 } catch ( error ) {
117114 toastMessage (
@@ -121,3 +118,12 @@ export async function actionGlobalOpenStateFile(pinia: Pinia) {
121118 console . error ( error )
122119 }
123120}
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