Skip to content

Commit 050fcbf

Browse files
committed
Add option and failing test
1 parent 9d1e913 commit 050fcbf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/getFlagsProxy.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ test('filters to target flags', () => {
5050

5151
expect(flags).toEqual({ fooBar: 'foobar' });
5252
});
53+
54+
test('does not use proxy if option is false', () => {
55+
const { flags } = getFlagsProxy(ldClient, rawFlags, { sendEventsOnFlagRead: false });
56+
57+
expect(flags['foo-bar']).toBe('foobar');
58+
59+
expect(variation).not.toHaveBeenCalled();
60+
});

src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ export interface LDReactOptions {
2121
* @see https://docs.launchdarkly.com/sdk/client-side/react/react-web#flag-keys
2222
*/
2323
useCamelCaseFlagKeys?: boolean;
24+
25+
/**
26+
* Whether to send flag evaluation events when a flag is read from the `flags` object
27+
* retured by the `useFlags` hook. This is true by default, meaning flag evaluation
28+
* events will be sent by default.
29+
*/
30+
sendEventsOnFlagRead?: boolean;
2431
}
2532

2633
/**
2734
* Contains default values for the `reactOptions` object.
2835
*/
29-
export const defaultReactOptions = { useCamelCaseFlagKeys: true };
36+
export const defaultReactOptions = { useCamelCaseFlagKeys: true, sendEventsOnFlagRead: true };
3037

3138
/**
3239
* Configuration object used to initialise LaunchDarkly's JS client.

0 commit comments

Comments
 (0)