Skip to content

Commit f1253c0

Browse files
authored
Merge pull request #78 from launchdarkly/christie/sc-164659/option-to-disable-proxy
Option to disable proxy
2 parents 9d1e913 + f9ca3a4 commit f1253c0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
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/getFlagsProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function getFlagsProxy(
2626
}
2727

2828
return {
29-
flags: toFlagsProxy(ldClient, flags, flagKeyMap),
29+
flags: reactOptions.sendEventsOnFlagRead ? toFlagsProxy(ldClient, flags, flagKeyMap) : flags,
3030
_flags: filteredFlags,
3131
flagKeyMap,
3232
};

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)