Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useSplitContext and remove SplitContext from exports #210

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
2.0.0 (October XX, 2024)
- Added support for targeting rules based on large segments for browsers.
- Added the `useSplitContext` hook to access the Split context value directly, although it should probably not be used frequently.
- Updated @splitsoftware/splitio package to version 10.29.0 that includes minor updates, and updated some transitive dependencies for vulnerability fixes.
- Renamed distribution folders from `/lib` to `/cjs` for CommonJS build, and `/es` to `/esm` for EcmaScript Modules build.
- BREAKING CHANGES:
- Updated error handling: using the library modules without wrapping them in a `SplitFactoryProvider` component will now throw an error instead of logging it, as the modules requires the `SplitContext` to work properly.
- Removed the export of the `SplitContext` object from the library index. The Split context value can be retrieved with the `useSplitContext` hook.
- Removed deprecated modules: `SplitFactory` component, `useClient`, `useTreatments` and `useManager` hooks, and `withSplitFactory`, `withSplitClient` and `withSplitTreatments` high-order components. Refer to ./MIGRATION-GUIDE.md for instructions on how to migrate to the new alternatives.
- Renamed TypeScript interfaces `ISplitFactoryProps` to `ISplitFactoryProviderProps`, and `ISplitFactoryChildProps` to `ISplitFactoryProviderChildProps`.
- Renamed `SplitSdk` to `SplitFactory` function, which is the underlying Split SDK factory, i.e., `import { SplitFactory } from '@splitsoftware/splitio'`.
Expand Down
9 changes: 3 additions & 6 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
SplitContext as ExportedSplitContext,
SplitFactory as ExportedSplitFactory,
SplitFactoryProvider as ExportedSplitFactoryProvider,
SplitClient as ExportedSplitClient,
Expand All @@ -9,6 +8,7 @@ import {
useSplitClient as exportedUseSplitClient,
useSplitTreatments as exportedUseSplitTreatments,
useSplitManager as exportedUseSplitManager,
useSplitContext as exportedUseSplitContext,
// Checks that types are exported. Otherwise, the test would fail with a TS error.
GetTreatmentsOptions,
ISplitClientChildProps,
Expand All @@ -23,7 +23,6 @@ import {
IUseSplitClientOptions,
IUseSplitTreatmentsOptions,
} from '../index';
import { SplitContext } from '../SplitContext';
import { SplitFactory } from '@splitsoftware/splitio/client';
import { SplitFactoryProvider } from '../SplitFactoryProvider';
import { SplitClient } from '../SplitClient';
Expand All @@ -32,6 +31,7 @@ import { useTrack } from '../useTrack';
import { useSplitClient } from '../useSplitClient';
import { useSplitTreatments } from '../useSplitTreatments';
import { useSplitManager } from '../useSplitManager';
import { useSplitContext } from '../SplitContext';

describe('index', () => {

Expand All @@ -46,10 +46,7 @@ describe('index', () => {
expect(exportedUseSplitClient).toBe(useSplitClient);
expect(exportedUseSplitTreatments).toBe(useSplitTreatments);
expect(exportedUseSplitManager).toBe(useSplitManager);
});

it('should export SplitContext', () => {
expect(ExportedSplitContext).toBe(SplitContext);
expect(exportedUseSplitContext).toBe(useSplitContext);
});

it('should export SplitFactory', () => {
Expand Down
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export { useTrack } from './useTrack';
export { useSplitClient } from './useSplitClient';
export { useSplitTreatments } from './useSplitTreatments';
export { useSplitManager } from './useSplitManager';

// SplitContext
export { SplitContext } from './SplitContext';
export { useSplitContext } from './SplitContext';

// Types
export type {
Expand Down
4 changes: 2 additions & 2 deletions umd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {
SplitFactory,
SplitFactoryProvider, SplitClient, SplitTreatments,
useSplitClient, useSplitTreatments, useTrack, useSplitManager,
SplitContext,
useSplitContext,
} from './src/index';

export default {
SplitFactory,
SplitFactoryProvider, SplitClient, SplitTreatments,
useSplitClient, useSplitTreatments, useTrack, useSplitManager,
SplitContext,
useSplitContext,
};
Loading