diff --git a/src/asyncWithLDProvider.tsx b/src/asyncWithLDProvider.tsx index d2685b1..2044783 100644 --- a/src/asyncWithLDProvider.tsx +++ b/src/asyncWithLDProvider.tsx @@ -1,10 +1,11 @@ import React, { useState, useEffect, ReactNode } from 'react'; import { initialize, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk'; -import { AsyncProviderConfig, defaultReactOptions, ProviderState } from './types'; +import { AsyncProviderConfig, defaultReactOptions } from './types'; import { Provider } from './context'; import { fetchFlags, getContextOrUser, getFlattenedFlagsFromChangeset } from './utils'; import getFlagsProxy from './getFlagsProxy'; import wrapperOptions from './wrapperOptions'; +import ProviderState from './providerState'; /** * This is an async function which initializes LaunchDarkly's JS SDK (`launchdarkly-js-client-sdk`) diff --git a/src/provider.test.tsx b/src/provider.test.tsx index dca037c..1396c5a 100644 --- a/src/provider.test.tsx +++ b/src/provider.test.tsx @@ -1,3 +1,5 @@ +import ProviderState from './providerState'; + jest.mock('launchdarkly-js-client-sdk', () => { const actual = jest.requireActual('launchdarkly-js-client-sdk'); @@ -19,7 +21,7 @@ jest.mock('./context', () => ({ Provider: 'Provider' })); import React, { Component } from 'react'; import { create } from 'react-test-renderer'; import { initialize, LDClient, LDContext, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk'; -import { LDReactOptions, EnhancedComponent, ProviderConfig, ProviderState } from './types'; +import { LDReactOptions, EnhancedComponent, ProviderConfig } from './types'; import { ReactSdkContext as HocState } from './context'; import LDProvider from './provider'; import { fetchFlags } from './utils'; diff --git a/src/provider.tsx b/src/provider.tsx index c3bb20a..c741ec3 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -1,10 +1,11 @@ import React, { Component, PropsWithChildren } from 'react'; import { initialize, LDClient, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk'; -import { EnhancedComponent, ProviderConfig, defaultReactOptions, LDReactOptions, ProviderState } from './types'; -import { Provider, ReactSdkContext } from './context'; +import { EnhancedComponent, ProviderConfig, defaultReactOptions, LDReactOptions } from './types'; +import { Provider } from './context'; import { camelCaseKeys, fetchFlags, getContextOrUser, getFlattenedFlagsFromChangeset } from './utils'; import getFlagsProxy from './getFlagsProxy'; import wrapperOptions from './wrapperOptions'; +import ProviderState from './providerState'; /** * The `LDProvider` is a component which accepts a config object which is used to diff --git a/src/providerState.ts b/src/providerState.ts new file mode 100644 index 0000000..62f47ce --- /dev/null +++ b/src/providerState.ts @@ -0,0 +1,12 @@ +import { LDClient, LDFlagSet } from 'launchdarkly-js-client-sdk'; +import { LDFlagKeyMap } from './types'; + +interface ProviderState { + error?: Error; + flagKeyMap: LDFlagKeyMap; + flags: LDFlagSet; + ldClient?: LDClient; + unproxiedFlags: LDFlagSet; +} + +export default ProviderState; diff --git a/src/types.ts b/src/types.ts index 393704a..ed96f3d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,5 @@ import { LDClient, LDContext, LDFlagSet, LDOptions } from 'launchdarkly-js-client-sdk'; import * as React from 'react'; -import { ReactSdkContext } from './context'; /** * Initialization options for the LaunchDarkly React SDK. These are in addition to the options exposed @@ -96,8 +95,9 @@ export interface ProviderConfig { /** * The amount of time, in seconds, to wait for initialization before rejecting the promise. * Using a large timeout is not recommended. If you use a large timeout and await it, then - * any network delays will cause your application to wait a long time before - * continuing execution. + * any network delays will cause your application to wait a long time before continuing + * execution. This gets passed to the underlying Javascript SDK `waitForInitialization` + * function. */ timeout?: number; } @@ -156,12 +156,4 @@ export interface LDFlagKeyMap { [camelCasedKey: string]: string; } -export interface ProviderState { - error?: Error; - flagKeyMap: LDFlagKeyMap; - flags: LDFlagSet; - ldClient?: LDClient; - unproxiedFlags: LDFlagSet; -} - export * from 'launchdarkly-js-client-sdk'; diff --git a/src/withLDProvider.test.tsx b/src/withLDProvider.test.tsx index a644991..ccb4d0e 100644 --- a/src/withLDProvider.test.tsx +++ b/src/withLDProvider.test.tsx @@ -22,9 +22,10 @@ import * as React from 'react'; import { create } from 'react-test-renderer'; import { initialize, LDContext, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk'; import withLDProvider from './withLDProvider'; -import { EnhancedComponent, ProviderState } from './types'; +import { EnhancedComponent } from './types'; import LDProvider from './provider'; import { fetchFlags } from './utils'; +import ProviderState from './providerState'; const clientSideID = 'test-client-side-id'; const App = () =>