Skip to content

Commit 6f3ad5c

Browse files
authored
feat: Support a pre-initialized client using asyncWithLDProvider. (#310)
1 parent ca1fdbb commit 6f3ad5c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/asyncWithLDProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
3838
let error: Error;
3939
let fetchedFlags = {};
4040

41-
const ldClient = initialize(clientSideID, context, { ...wrapperOptions, ...options });
41+
const ldClient = (await config.ldClient) ?? initialize(clientSideID, context, { ...wrapperOptions, ...options });
4242
try {
4343
await ldClient.waitForInitialization(config.timeout);
4444
fetchedFlags = fetchFlags(ldClient, targetFlags);

src/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ export interface ProviderConfig {
8585
flags?: LDFlagSet;
8686

8787
/**
88-
* Optionally, the ldClient can be initialised outside of the provider
89-
* and passed in, instead of being initialised by the provider.
88+
* Optionally, the ldClient can be initialized outside of the provider
89+
* and passed in, instead of being initialized by the provider.
90+
*
9091
* Note: it should only be passed in when it has emitted the 'ready'
91-
* event, to ensure that the flags are properly set.
92+
* event when using withLDProvider, to ensure that the flags are properly set.
93+
* If using with asyncWithLDProvider, then it will wait internally, so
94+
* it is not required that the client have emitted the 'ready' event.
9295
*/
9396
ldClient?: LDClient | Promise<LDClient | undefined>;
9497

0 commit comments

Comments
 (0)