@@ -92,30 +92,32 @@ export class Frigade extends Fetchable {
9292 apiKey,
9393 ...config ,
9494 } )
95- this . init ( this . config )
96- if ( isWeb ( ) && this . config . syncOnWindowUpdates !== false ) {
97- document . addEventListener ( 'visibilitychange' , this . visibilityChangeHandler )
98- // @ts -ignore
99- if ( window . navigation ) {
95+ this . init ( this . config ) . then ( ( ) => {
96+ if ( isWeb ( ) && this . config . syncOnWindowUpdates !== false ) {
97+ document . addEventListener ( 'visibilitychange' , this . visibilityChangeHandler )
10098 // @ts -ignore
101- window . navigation . addEventListener ( 'navigate' , async ( event ) => {
102- try {
103- if ( this . getGlobalState ( ) . currentUrl === event . destination . url ) {
104- return
105- }
106- // if the new base url is the same but with a hashtag, don't refresh the state as the page has not changed.
107- if (
108- event . destination . url &&
109- this . getGlobalState ( ) . currentUrl &&
110- event . destination . url . split ( '#' ) [ 0 ] === this . getGlobalState ( ) . currentUrl . split ( '#' ) [ 0 ]
111- ) {
112- return
113- }
114- this . queueRefreshStateFromAPI ( )
115- } catch ( e ) { }
116- } )
99+ if ( window . navigation ) {
100+ // @ts -ignore
101+ window . navigation . addEventListener ( 'navigate' , async ( event ) => {
102+ try {
103+ if ( this . getGlobalState ( ) . currentUrl === event . destination . url ) {
104+ return
105+ }
106+ // if the new base url is the same but with a hashtag, don't refresh the state as the page has not changed.
107+ if (
108+ event . destination . url &&
109+ this . getGlobalState ( ) . currentUrl &&
110+ event . destination . url . split ( '#' ) [ 0 ] ===
111+ this . getGlobalState ( ) . currentUrl . split ( '#' ) [ 0 ]
112+ ) {
113+ return
114+ }
115+ this . queueRefreshStateFromAPI ( )
116+ } catch ( e ) { }
117+ } )
118+ }
117119 }
118- }
120+ } )
119121 }
120122
121123 /**
@@ -280,7 +282,12 @@ export class Frigade extends Fetchable {
280282 * @ignore
281283 */
282284 public isReady ( ) : boolean {
283- return Boolean ( this . config . __instanceId && this . config . apiKey && this . initPromise )
285+ return Boolean (
286+ this . config . __instanceId &&
287+ this . config . apiKey &&
288+ this . initPromise &&
289+ frigadeGlobalState [ getGlobalStateKey ( this . config ) ]
290+ )
284291 }
285292
286293 /**
0 commit comments