Skip to content

Commit

Permalink
Adds a hook to listen for async storage load (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-statsig committed Jun 9, 2023
1 parent 147198e commit bac8753
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/StatsigClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bac8753

Please sign in to comment.