Skip to content

Commit 61a1008

Browse files
committed
Merge branch 'main' into christie/sc-162898/fix-react-sdk-tests
2 parents 431984b + aee0864 commit 61a1008

File tree

6 files changed

+33
-42
lines changed

6 files changed

+33
-42
lines changed

examples/async-provider/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,9 +2886,9 @@ events@^3.0.0:
28862886
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
28872887

28882888
eventsource@^1.0.7:
2889-
version "1.1.0"
2890-
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.0.tgz#00e8ca7c92109e94b0ddf32dac677d841028cfaf"
2891-
integrity sha512-VSJjT5oCNrFvCS6igjzPAt5hBzQ2qPBFIbJ03zLI9SE0mxwZpMw6BfJrbFHm1a141AavMEB8JHmBhWAd66PfCg==
2889+
version "1.1.1"
2890+
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.1.tgz#4544a35a57d7120fba4fa4c86cb4023b2c09df2f"
2891+
integrity sha512-qV5ZC0h7jYIAOhArFJgSfdyz6rALJyb270714o7ZtNnw2WSJ+eexhKtE0O8LYPRsHZHf2osHKZBxGPvm3kPkCA==
28922892
dependencies:
28932893
original "^1.0.0"
28942894

@@ -6144,9 +6144,9 @@ source-map-resolve@^0.5.0:
61446144
urix "^0.1.0"
61456145

61466146
source-map-support@~0.5.12:
6147-
version "0.5.19"
6148-
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
6149-
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
6147+
version "0.5.21"
6148+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
6149+
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
61506150
dependencies:
61516151
buffer-from "^1.0.0"
61526152
source-map "^0.6.0"
@@ -6467,9 +6467,9 @@ terser-webpack-plugin@^1.4.3:
64676467
worker-farm "^1.7.0"
64686468

64696469
terser@^4.1.2:
6470-
version "4.8.0"
6471-
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
6472-
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
6470+
version "4.8.1"
6471+
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.1.tgz#a00e5634562de2239fd404c649051bf6fc21144f"
6472+
integrity sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==
64736473
dependencies:
64746474
commander "^2.20.0"
64756475
source-map "~0.6.1"

examples/hoc/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,9 +3063,9 @@ events@^3.0.0:
30633063
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
30643064

30653065
eventsource@^1.0.7:
3066-
version "1.1.0"
3067-
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.0.tgz#00e8ca7c92109e94b0ddf32dac677d841028cfaf"
3068-
integrity sha512-VSJjT5oCNrFvCS6igjzPAt5hBzQ2qPBFIbJ03zLI9SE0mxwZpMw6BfJrbFHm1a141AavMEB8JHmBhWAd66PfCg==
3066+
version "1.1.1"
3067+
resolved "https://registry.yarnpkg.com/eventsource/-/eventsource-1.1.1.tgz#4544a35a57d7120fba4fa4c86cb4023b2c09df2f"
3068+
integrity sha512-qV5ZC0h7jYIAOhArFJgSfdyz6rALJyb270714o7ZtNnw2WSJ+eexhKtE0O8LYPRsHZHf2osHKZBxGPvm3kPkCA==
30693069
dependencies:
30703070
original "^1.0.0"
30713071

@@ -6411,9 +6411,9 @@ source-map-resolve@^0.5.0:
64116411
urix "^0.1.0"
64126412

64136413
source-map-support@~0.5.12:
6414-
version "0.5.19"
6415-
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
6416-
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
6414+
version "0.5.21"
6415+
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.21.tgz#04fe7c7f9e1ed2d662233c28cb2b35b9f63f6e4f"
6416+
integrity sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==
64176417
dependencies:
64186418
buffer-from "^1.0.0"
64196419
source-map "^0.6.0"
@@ -6729,9 +6729,9 @@ terser-webpack-plugin@^1.4.3:
67296729
worker-farm "^1.7.0"
67306730

67316731
terser@^4.1.2:
6732-
version "4.8.0"
6733-
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
6734-
integrity sha512-EAPipTNeWsb/3wLPeup1tVPaXfIaU68xMnVdPafIL1TV05OhASArYyIfFvnvJCNrR2NIOvDVNNTFRa+Re2MWyw==
6732+
version "4.8.1"
6733+
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.1.tgz#a00e5634562de2239fd404c649051bf6fc21144f"
6734+
integrity sha512-4GnLC0x667eJG0ewJTa6z/yXrbLGv80D9Ru6HIpCQmO+Q4PfEtBFi0ObSckqwL6VyQv/7ENJieXHo2ANmdQwgw==
67356735
dependencies:
67366736
commander "^2.20.0"
67376737
source-map "~0.6.1"

src/initLDClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { initialize as ldClientInitialize, LDFlagSet, LDOptions, LDUser } from 'launchdarkly-js-client-sdk';
22
import { AllFlagsLDClient, defaultReactOptions, LDReactOptions } from './types';
33
import { fetchFlags } from './utils';
4-
import { version } from '../package.json';
4+
import * as packageInfo from '../package.json';
55

66
/**
77
* Internal function to initialize the `LDClient`.
@@ -22,7 +22,7 @@ const initLDClient = async (
2222
options?: LDOptions,
2323
targetFlags?: LDFlagSet,
2424
): Promise<AllFlagsLDClient> => {
25-
const allOptions = { wrapperName: 'react-client-sdk', wrapperVersion: version, ...options };
25+
const allOptions = { wrapperName: 'react-client-sdk', wrapperVersion: packageInfo.version, ...options };
2626
const ldClient = ldClientInitialize(clientSideID, user, allOptions);
2727

2828
return new Promise<AllFlagsLDClient>((resolve) => {

src/useFlags.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { LDFlagSet } from 'launchdarkly-js-client-sdk';
12
import { useContext } from 'react';
2-
import context from './context';
3+
import context, { LDContext } from './context';
34

45
/**
56
* `useFlags` is a custom hook which returns all feature flags. It uses the `useContext` primitive
@@ -9,10 +10,10 @@ import context from './context';
910
*
1011
* @return All the feature flags configured in your LaunchDarkly project
1112
*/
12-
const useFlags = () => {
13-
const { flags } = useContext(context);
13+
const useFlags = <T extends LDFlagSet = LDFlagSet>(): T => {
14+
const { flags } = useContext<LDContext>(context);
1415

15-
return flags;
16+
return flags as T;
1617
};
1718

1819
export default useFlags;

src/withLDConsumer.test.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ describe('withLDConsumer', () => {
3333
});
3434

3535
test('ldClient is passed down through context api', () => {
36-
const Home = (props: HocProps) => (
37-
<div>
38-
{props.ldClient && Object.hasOwnProperty.call(props.ldClient, 'track')
39-
? 'ldClient detected'
40-
: 'Negative, no ldClient'}
41-
</div>
42-
);
36+
const Home = (props: HocProps) => <div>{props.ldClient ? 'ldClient detected' : 'Negative, no ldClient'}</div>;
4337
const HomeWithFlags = withLDConsumer()(Home);
4438
const component = create(<HomeWithFlags />);
4539
expect(component).toMatchSnapshot();
@@ -49,9 +43,7 @@ describe('withLDConsumer', () => {
4943
const Home = (props: HocProps) => (
5044
<div>
5145
{props.flags ? 'flags detected' : 'Negative, no flag'}
52-
{props.ldClient && Object.hasOwnProperty.call(props.ldClient, 'track')
53-
? 'ldClient detected'
54-
: 'Negative, no ldClient'}
46+
{props.ldClient ? 'ldClient detected' : 'Negative, no ldClient'}
5547
</div>
5648
);
5749
const HomeWithFlags = withLDConsumer({ clientOnly: true })(Home);

src/withLDProvider.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ export function withLDProvider<T = {}>(
3131
const reactOptions = { ...defaultReactOptions, ...userReactOptions };
3232
const providerProps = { ...config, reactOptions };
3333

34-
class HoistedComponent extends React.Component<T> {
35-
render() {
36-
return (
37-
<LDProvider {...providerProps}>
38-
<WrappedComponent {...this.props} />
39-
</LDProvider>
40-
);
41-
}
34+
function HoistedComponent(props: T) {
35+
return (
36+
<LDProvider {...providerProps}>
37+
<WrappedComponent {...props} />
38+
</LDProvider>
39+
);
4240
}
4341

4442
hoistNonReactStatics(HoistedComponent, WrappedComponent);

0 commit comments

Comments
 (0)