Skip to content

Commit 2cc2b28

Browse files
authored
refactor: Renamed decide hook from useDecide to useDecision (#105)
## Summary Renamed decide hook from `useDecide` to `useDecision`. ## Test Plan 1. Manually tested thoroughly. 2. Updated unit tests.
1 parent 8dc7734 commit 2cc2b28

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/hooks.spec.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { act } from 'react-dom/test-utils';
2020

2121
import { OptimizelyProvider } from './Provider';
2222
import { OnReadyResult, ReactSDKClient, VariableValuesObject } from './client';
23-
import { useExperiment, useFeature, useDecide } from './hooks';
23+
import { useExperiment, useFeature, useDecision } from './hooks';
2424
import { OptimizelyDecision } from './utils';
2525

2626
Enzyme.configure({ adapter: new Adapter() });
@@ -46,7 +46,7 @@ const MyExperimentComponent = ({ options = {}, overrides = {} }: any) => {
4646
};
4747

4848
const MyDecideComponent = ({ options = {}, overrides = {} }: any) => {
49-
const [decision, clientReady, didTimeout] = useDecide('feature1', { ...options }, { ...overrides });
49+
const [decision, clientReady, didTimeout] = useDecision('feature1', { ...options }, { ...overrides });
5050
return <>{`${(decision.enabled) ? 'true' : 'false'}|${JSON.stringify(decision.variables)}|${clientReady}|${didTimeout}`}</>;
5151
};
5252

@@ -66,7 +66,7 @@ describe('hooks', () => {
6666
let userUpdateCallbacks: Array<() => void>;
6767
let UseExperimentLoggingComponent: React.FunctionComponent<any>;
6868
let UseFeatureLoggingComponent: React.FunctionComponent<any>;
69-
let UseDecideLoggingComponent: React.FunctionComponent<any>;
69+
let UseDecisionLoggingComponent: React.FunctionComponent<any>;
7070
let mockLog: jest.Mock;
7171
let forcedVariationUpdateCallbacks: Array<() => void>;
7272
let decideMock: jest.Mock<OptimizelyDecision>;
@@ -139,8 +139,8 @@ describe('hooks', () => {
139139
return <div>{isEnabled}</div>;
140140
};
141141

142-
UseDecideLoggingComponent = ({ options = {}, overrides = {} }: any) => {
143-
const [decision] = useDecide('feature1', { ...options }, { ...overrides });
142+
UseDecisionLoggingComponent = ({ options = {}, overrides = {} }: any) => {
143+
const [decision] = useDecision('feature1', { ...options }, { ...overrides });
144144
mockLog(decision.enabled);
145145
return <div>{decision.enabled}</div>;
146146
};
@@ -668,7 +668,7 @@ describe('hooks', () => {
668668
});
669669
});
670670

671-
describe('useDecide', () => {
671+
describe('useDecision', () => {
672672
it('should render true when the flag is enabled', async () => {
673673
decideMock.mockReturnValue({
674674
... defaultDecision,
@@ -813,7 +813,7 @@ describe('hooks', () => {
813813
decideMock.mockReturnValue({ ...defaultDecision });
814814
const component = Enzyme.mount(
815815
<OptimizelyProvider optimizely={optimizelyMock}>
816-
<UseDecideLoggingComponent />
816+
<UseDecisionLoggingComponent />
817817
</OptimizelyProvider>
818818
);
819819
component.update();
@@ -835,7 +835,7 @@ describe('hooks', () => {
835835

836836
const component = Enzyme.mount(
837837
<OptimizelyProvider optimizely={optimizelyMock}>
838-
<UseDecideLoggingComponent />
838+
<UseDecisionLoggingComponent />
839839
</OptimizelyProvider>
840840
);
841841
component.update();
@@ -914,7 +914,7 @@ describe('hooks', () => {
914914
decideMock.mockReturnValue({ ...defaultDecision });
915915
const component = Enzyme.mount(
916916
<OptimizelyProvider optimizely={optimizelyMock}>
917-
<UseDecideLoggingComponent
917+
<UseDecisionLoggingComponent
918918
options={{ autoUpdate: true }}
919919
overrides={{ overrideAttributes: { other_attr: 'y' } }}
920920
/>
@@ -924,7 +924,7 @@ describe('hooks', () => {
924924
decideMock.mockReset();
925925
component.setProps({
926926
children: (
927-
<UseDecideLoggingComponent
927+
<UseDecisionLoggingComponent
928928
options={{ autoUpdate: true }}
929929
overrides={{ overrideAttributes: { other_attr: 'y' } }}
930930
/>

src/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ interface UseFeature {
7979
];
8080
}
8181

82-
interface UseDecide {
82+
interface UseDecision {
8383
(featureKey: string, options?: DecideHooksOptions, overrides?: HookOverrides): [
8484
OptimizelyDecision,
8585
ClientReady,
@@ -329,7 +329,7 @@ export const useFeature: UseFeature = (featureKey, options = {}, overrides = {})
329329
* Note: The react client can become ready AFTER the timeout period.
330330
* ClientReady and DidTimeout provide signals to handle this scenario.
331331
*/
332-
export const useDecide: UseDecide = (flagKey, options = {}, overrides = {}) => {
332+
export const useDecision: UseDecision = (flagKey, options = {}, overrides = {}) => {
333333
const { optimizely, isServerSide, timeout } = useContext(OptimizelyContext);
334334
if (!optimizely) {
335335
throw new Error('optimizely prop must be supplied via a parent <OptimizelyProvider>');

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
export { OptimizelyContext, OptimizelyContextConsumer, OptimizelyContextProvider } from './Context';
1717
export { OptimizelyProvider } from './Provider';
1818
export { OptimizelyFeature } from './Feature';
19-
export { useFeature, useExperiment, useDecide } from './hooks';
19+
export { useFeature, useExperiment, useDecision } from './hooks';
2020
export { withOptimizely, WithOptimizelyProps, WithoutOptimizelyProps } from './withOptimizely';
2121
export { OptimizelyExperiment } from './Experiment';
2222
export { OptimizelyVariation } from './Variation';

0 commit comments

Comments
 (0)