Skip to content

Commit fc4ff11

Browse files
authored
chore: Make ProviderState internal. (#149)
* Make ProviderState internal. * Remove unused imports. * Improved timeout comments
1 parent 338d85a commit fc4ff11

File tree

6 files changed

+25
-16
lines changed

6 files changed

+25
-16
lines changed

src/asyncWithLDProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useState, useEffect, ReactNode } from 'react';
22
import { initialize, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk';
3-
import { AsyncProviderConfig, defaultReactOptions, ProviderState } from './types';
3+
import { AsyncProviderConfig, defaultReactOptions } from './types';
44
import { Provider } from './context';
55
import { fetchFlags, getContextOrUser, getFlattenedFlagsFromChangeset } from './utils';
66
import getFlagsProxy from './getFlagsProxy';
77
import wrapperOptions from './wrapperOptions';
8+
import ProviderState from './providerState';
89

910
/**
1011
* This is an async function which initializes LaunchDarkly's JS SDK (`launchdarkly-js-client-sdk`)

src/provider.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import ProviderState from './providerState';
2+
13
jest.mock('launchdarkly-js-client-sdk', () => {
24
const actual = jest.requireActual('launchdarkly-js-client-sdk');
35

@@ -19,7 +21,7 @@ jest.mock('./context', () => ({ Provider: 'Provider' }));
1921
import React, { Component } from 'react';
2022
import { create } from 'react-test-renderer';
2123
import { initialize, LDClient, LDContext, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk';
22-
import { LDReactOptions, EnhancedComponent, ProviderConfig, ProviderState } from './types';
24+
import { LDReactOptions, EnhancedComponent, ProviderConfig } from './types';
2325
import { ReactSdkContext as HocState } from './context';
2426
import LDProvider from './provider';
2527
import { fetchFlags } from './utils';

src/provider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { Component, PropsWithChildren } from 'react';
22
import { initialize, LDClient, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';
3-
import { EnhancedComponent, ProviderConfig, defaultReactOptions, LDReactOptions, ProviderState } from './types';
4-
import { Provider, ReactSdkContext } from './context';
3+
import { EnhancedComponent, ProviderConfig, defaultReactOptions, LDReactOptions } from './types';
4+
import { Provider } from './context';
55
import { camelCaseKeys, fetchFlags, getContextOrUser, getFlattenedFlagsFromChangeset } from './utils';
66
import getFlagsProxy from './getFlagsProxy';
77
import wrapperOptions from './wrapperOptions';
8+
import ProviderState from './providerState';
89

910
/**
1011
* The `LDProvider` is a component which accepts a config object which is used to

src/providerState.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { LDClient, LDFlagSet } from 'launchdarkly-js-client-sdk';
2+
import { LDFlagKeyMap } from './types';
3+
4+
interface ProviderState {
5+
error?: Error;
6+
flagKeyMap: LDFlagKeyMap;
7+
flags: LDFlagSet;
8+
ldClient?: LDClient;
9+
unproxiedFlags: LDFlagSet;
10+
}
11+
12+
export default ProviderState;

src/types.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { LDClient, LDContext, LDFlagSet, LDOptions } from 'launchdarkly-js-client-sdk';
22
import * as React from 'react';
3-
import { ReactSdkContext } from './context';
43

54
/**
65
* Initialization options for the LaunchDarkly React SDK. These are in addition to the options exposed
@@ -96,8 +95,9 @@ export interface ProviderConfig {
9695
/**
9796
* The amount of time, in seconds, to wait for initialization before rejecting the promise.
9897
* Using a large timeout is not recommended. If you use a large timeout and await it, then
99-
* any network delays will cause your application to wait a long time before
100-
* continuing execution.
98+
* any network delays will cause your application to wait a long time before continuing
99+
* execution. This gets passed to the underlying Javascript SDK `waitForInitialization`
100+
* function.
101101
*/
102102
timeout?: number;
103103
}
@@ -156,12 +156,4 @@ export interface LDFlagKeyMap {
156156
[camelCasedKey: string]: string;
157157
}
158158

159-
export interface ProviderState {
160-
error?: Error;
161-
flagKeyMap: LDFlagKeyMap;
162-
flags: LDFlagSet;
163-
ldClient?: LDClient;
164-
unproxiedFlags: LDFlagSet;
165-
}
166-
167159
export * from 'launchdarkly-js-client-sdk';

src/withLDProvider.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import * as React from 'react';
2222
import { create } from 'react-test-renderer';
2323
import { initialize, LDContext, LDFlagChangeset, LDOptions } from 'launchdarkly-js-client-sdk';
2424
import withLDProvider from './withLDProvider';
25-
import { EnhancedComponent, ProviderState } from './types';
25+
import { EnhancedComponent } from './types';
2626
import LDProvider from './provider';
2727
import { fetchFlags } from './utils';
28+
import ProviderState from './providerState';
2829

2930
const clientSideID = 'test-client-side-id';
3031
const App = () => <div>My App</div>;

0 commit comments

Comments
 (0)