Skip to content

Commit

Permalink
chore: Make ProviderState internal. (#149)
Browse files Browse the repository at this point in the history
* Make ProviderState internal.
* Remove unused imports.
* Improved timeout comments
  • Loading branch information
yusinto authored May 20, 2024
1 parent 338d85a commit fc4ff11
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/asyncWithLDProvider.tsx
Original file line number Diff line number Diff line change
@@ -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`)
Expand Down
4 changes: 3 additions & 1 deletion src/provider.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ProviderState from './providerState';

jest.mock('launchdarkly-js-client-sdk', () => {
const actual = jest.requireActual('launchdarkly-js-client-sdk');

Expand All @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions src/provider.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/providerState.ts
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 3 additions & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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';
3 changes: 2 additions & 1 deletion src/withLDProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => <div>My App</div>;
Expand Down

0 comments on commit fc4ff11

Please sign in to comment.