@@ -17,39 +17,45 @@ const mainStore = localforage.createInstance({
1717// the delay to set
1818
1919function persistStore ( store , transform ) {
20- autorunAsync ( ( ) => {
21- const customTransform = transform || createTransformer ( store => mobxToJS ( store ) )
22- const transformedPluginStore = mobxToJS ( pluginSettingStore )
23- const transformedStore = customTransform ( store )
24- // 初次等spacekey出现存
25- if ( config . spaceKey && ! mainStore . _config . storeName ) {
26- mainStore . config ( { storeName : config . spaceKey } )
27- } else if ( mainStore . _config . storeName && ( config . globalKey || ! config . isPlatform ) ) {
28- if ( config . hasRehydrated ) {
29- mainStore . setItem ( `${ config . spaceKey } .${ config . globalKey } ` , transformedStore )
30- mainStore . setItem ( `${ config . spaceKey } .${ config . globalKey } .plugins` , transformedPluginStore )
31- } else {
32- mainStore . getItem ( `${ config . spaceKey } .${ config . globalKey } ` ) . then ( ( store ) => {
33- if ( store ) {
34- autoRehydrate ( store )
35- } else {
36- dispatchCommand ( 'global:show_env' )
37- dispatchCommand ( 'file:open_welcome' )
38- }
39- fileState . initData . set ( '_init' , false )
40- config . hasRehydrated = true
41- } )
42- mainStore . getItem ( `${ config . spaceKey } .${ config . globalKey } .plugins` ) . then ( ( plugins ) => {
43- for ( const plugin in plugins ) {
44- pluginSettingStore [ plugin ] = observable ( plugins [ plugin ] )
45- }
46- if ( ! config . hasRehydrated ) {
47- config . hasRehydrated = true
48- }
49- } )
20+ return new Promise ( ( resolve , reject ) => {
21+ autorunAsync ( ( ) => {
22+ const customTransform = transform || createTransformer ( store => mobxToJS ( store ) )
23+ const transformedPluginStore = mobxToJS ( pluginSettingStore )
24+ const transformedStore = customTransform ( store )
25+ // 初次等spacekey出现存
26+ if ( config . spaceKey && ! mainStore . _config . storeName ) {
27+ mainStore . config ( { storeName : config . spaceKey } )
28+ } else if ( mainStore . _config . storeName && ( config . globalKey || ! config . isPlatform ) ) {
29+ if ( config . hasRehydrated ) {
30+ mainStore . setItem ( `${ config . spaceKey } .${ config . globalKey } ` , transformedStore )
31+ mainStore . setItem ( `${ config . spaceKey } .${ config . globalKey } .plugins` , transformedPluginStore )
32+ resolve ( true )
33+ } else {
34+ const tasks = [
35+ mainStore . getItem ( `${ config . spaceKey } .${ config . globalKey } ` ) ,
36+ mainStore . getItem ( `${ config . spaceKey } .${ config . globalKey } .plugins` )
37+ ]
38+ Promise . all ( tasks )
39+ . then ( ( [ store , pluginsStore ] ) => {
40+ if ( store ) {
41+ autoRehydrate ( store )
42+ } else {
43+ dispatchCommand ( 'global:show_env' )
44+ dispatchCommand ( 'file:open_welcome' )
45+ }
46+ fileState . initData . set ( '_init' , false )
47+
48+ for ( const plugin in pluginsStore ) {
49+ pluginSettingStore [ plugin ] = observable ( pluginsStore [ plugin ] )
50+ }
51+
52+ config . hasRehydrated = true
53+ resolve ( true )
54+ } )
55+ }
5056 }
51- }
52- } , 200 )
57+ } , 200 )
58+ } )
5359}
5460
5561export const clearPersist = ( key ) => {
0 commit comments