Skip to content

Commit d3db5e5

Browse files
Merge branch 'add_hooks' into refactor_no_default_export
2 parents e019112 + b5535b8 commit d3db5e5

8 files changed

Lines changed: 23 additions & 23 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
},
101101
"husky": {
102102
"hooks": {
103-
"pre-commit": "npm run check",
103+
"pre-commit": "npm run check && npm run build",
104104
"pre-push": "npm test && npm run build"
105105
}
106106
}

src/useClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useClientAndContext } from './useClientAndContext';
1+
import { useSplitClient } from './useSplitClient';
22

33
/**
44
* 'useClient' is a hook that returns a client from the Split context.
@@ -9,5 +9,5 @@ import { useClientAndContext } from './useClientAndContext';
99
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-instantiate-multiple-sdk-clients}
1010
*/
1111
export function useClient(key?: SplitIO.SplitKey, trafficType?: string, attributes?: SplitIO.Attributes): SplitIO.IBrowserClient | null {
12-
return useClientAndContext(key, trafficType, attributes).client;
12+
return useSplitClient(key, trafficType, attributes).client;
1313
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import { getSplitSharedClient, checkHooks, initAttributes, IClientWithContext }
55
import { ISplitContextValues } from './types';
66

77
/**
8-
* 'useClientAndContext' is a hook that returns an Split Context object with the client and its status corresponding to the provided key and trafficType.
8+
* 'useSplitClient' is a hook that returns an Split Context object with the client and its status corresponding to the provided key and trafficType.
99
* It uses the 'useContext' hook to access the context, which is updated by SplitFactory and SplitClient components in the hierarchy of components.
1010
*
1111
* @return A Split Context object
1212
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-instantiate-multiple-sdk-clients}
1313
*/
14-
export function useClientAndContext(key?: SplitIO.SplitKey, trafficType?: string, attributes?: SplitIO.Attributes): ISplitContextValues {
14+
export function useSplitClient(key?: SplitIO.SplitKey, trafficType?: string, attributes?: SplitIO.Attributes): ISplitContextValues {
1515
if (!checkHooks(ERROR_UC_NO_USECONTEXT)) return INITIAL_CONTEXT;
1616

1717
const context = React.useContext(SplitContext);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { getControlTreatmentsWithConfig, ERROR_UT_NO_USECONTEXT } from './consta
22
import { checkHooks, IClientWithContext } from './utils';
33
import { ISplitTreatmentsChildProps } from './types';
44
import { INITIAL_CONTEXT } from './SplitContext';
5-
import { useClientAndContext } from './useClientAndContext';
5+
import { useSplitClient } from './useSplitClient';
66

77
/**
8-
* 'useTreatmentsAndContext' is a hook that returns an SplitContext object extended with a `treatments` property containing an object of feature flag evaluations (i.e., treatments).
9-
* It uses the 'useClientAndContext' hook to access the client from the Split context, and invokes the 'getTreatmentsWithConfig' method.
8+
* 'useSplitTreatments' is a hook that returns an SplitContext object extended with a `treatments` property containing an object of feature flag evaluations (i.e., treatments).
9+
* It uses the 'useSplitClient' hook to access the client from the Split context, and invokes the 'getTreatmentsWithConfig' method.
1010
*
1111
* @return A Split Context object extended with a TreatmentsWithConfig instance, that might contain control treatments if the client is not available or ready, or if split names do not exist.
1212
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#get-treatments-with-configurations}
1313
*/
14-
export function useTreatmentsAndContext(splitNames: string[], attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): ISplitTreatmentsChildProps {
15-
const context = checkHooks(ERROR_UT_NO_USECONTEXT) ? useClientAndContext(key) : INITIAL_CONTEXT;
14+
export function useSplitTreatments(splitNames: string[], attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): ISplitTreatmentsChildProps {
15+
const context = checkHooks(ERROR_UT_NO_USECONTEXT) ? useSplitClient(key) : INITIAL_CONTEXT;
1616
const client = context.client;
1717
const treatments = client && (client as IClientWithContext).__getStatus().isOperational ?
1818
client.getTreatmentsWithConfig(splitNames, attributes) :

src/useTreatments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useTreatmentsAndContext } from './useTreatmentsAndContext';
1+
import { useSplitTreatments } from './useSplitTreatments';
22

33
/**
44
* 'useTreatments' is a hook that returns an object of feature flag evaluations (i.e., treatments).
@@ -9,5 +9,5 @@ import { useTreatmentsAndContext } from './useTreatmentsAndContext';
99
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#get-treatments-with-configurations}
1010
*/
1111
export function useTreatments(featureFlagNames: string[], attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): SplitIO.TreatmentsWithConfig {
12-
return useTreatmentsAndContext(featureFlagNames, attributes, key).treatments;
12+
return useSplitTreatments(featureFlagNames, attributes, key).treatments;
1313
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ISplitContextValues } from './types';
22
/**
3-
* 'useClientAndContext' is a hook that returns an Split Context object with the client and its status corresponding to the provided key and trafficType.
3+
* 'useSplitClient' is a hook that returns an Split Context object with the client and its status corresponding to the provided key and trafficType.
44
* It uses the 'useContext' hook to access the context, which is updated by SplitFactory and SplitClient components in the hierarchy of components.
55
*
66
* @return A Split Context object
77
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-instantiate-multiple-sdk-clients}
88
*/
9-
export declare function useClientAndContext(key?: SplitIO.SplitKey, trafficType?: string, attributes?: SplitIO.Attributes): ISplitContextValues;
9+
export declare function useSplitClient(key?: SplitIO.SplitKey, trafficType?: string, attributes?: SplitIO.Attributes): ISplitContextValues;

types/useSplitTreatments.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ISplitTreatmentsChildProps } from './types';
2+
/**
3+
* 'useSplitTreatments' is a hook that returns an SplitContext object extended with a `treatments` property containing an object of feature flag evaluations (i.e., treatments).
4+
* It uses the 'useSplitClient' hook to access the client from the Split context, and invokes the 'getTreatmentsWithConfig' method.
5+
*
6+
* @return A Split Context object extended with a TreatmentsWithConfig instance, that might contain control treatments if the client is not available or ready, or if split names do not exist.
7+
* @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#get-treatments-with-configurations}
8+
*/
9+
export declare function useSplitTreatments(splitNames: string[], attributes?: SplitIO.Attributes, key?: SplitIO.SplitKey): ISplitTreatmentsChildProps;

types/useTreatmentsAndContext.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)