From bac87532312c783817a6519da62a2435b5200be6 Mon Sep 17 00:00:00 2001 From: Daniel <95646168+daniel-statsig@users.noreply.github.com> Date: Fri, 9 Jun 2023 13:32:03 -0700 Subject: [PATCH] Adds a hook to listen for async storage load (#337) --- src/StatsigClient.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/StatsigClient.ts b/src/StatsigClient.ts index c45df83..984d913 100644 --- a/src/StatsigClient.ts +++ b/src/StatsigClient.ts @@ -120,6 +120,7 @@ export default class StatsigClient implements IHasStatsigInternal, IStatsig { private static reactNativeUUID?: UUID; private appState: AppState | null = null; private currentAppState: AppStateStatus | null = null; + private onCacheLoadedForReact: (() => void) | null = null; private ready: boolean; private initCalled = false; @@ -311,12 +312,15 @@ export default class StatsigClient implements IHasStatsigInternal, IStatsig { DiagnosticsKey.OVERALL, DiagnosticsEvent.START, ); + this.initCalled = true; if (StatsigAsyncStorage.asyncStorage) { await this.identity.initAsync(); await this.store.loadFromAsyncStorage(); } + this.onCacheLoadedForReact?.(); + if ( this.appState && this.appState.addEventListener && @@ -882,6 +886,10 @@ export default class StatsigClient implements IHasStatsigInternal, IStatsig { } } + public setOnCacheLoadedReactCallback(fn?: (() => void) | null) { + this.onCacheLoadedForReact = fn ?? null; + } + public static setReactNativeUUID(uuid?: UUID | null): void { if (uuid != null) { StatsigClient.reactNativeUUID = uuid;