diff --git a/CHANGES.txt b/CHANGES.txt index f5e3410..441f867 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,8 @@ -1.14.0 (September 12, 2024) +1.14.0 (September 13, 2024) - Added `status` property to Split reducer's slice of state to track the SDK events of non-default clients (Related to https://github.com/splitio/redux-client/issues/113). - Added `lastUpdate` and `isTimedout` properties to the object returned by the `getStatus` helper and `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors, to expose the last event timestamp and the timedout status of the SDK clients (Related to https://github.com/splitio/redux-client/issues/113). + - Added `selectStatus` selector to retrieve the status properties of the SDK manager and clients from the Split state. + - Added remaining TypeScript types and interfaces to the library index exports, allowing them to be imported from the library index in TypeScript, e.g., `import type { IInitSplitSdkParams } from '@splitsoftware/splitio-redux'`. - Updated `selectTreatmentAndStatus` and `selectTreatmentWithConfigAndStatus` selectors to retrieve status properties from the state rather than the SDK client instances directly. - Updated @splitsoftware/splitio package to version 10.28.0 that includes minor updates: - Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks. diff --git a/src/helpers.ts b/src/helpers.ts index 73a12ee..4b658ac 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -87,12 +87,10 @@ export function getSplits(): SplitIO.SplitViews { } /** - * Gets an object with the status properties of the SDK client or manager: + * Gets an object with the status properties of the SDK client or manager. * - * - `isReady` indicates if the SDK client has emitted the SDK_READY event. - * - `isReadyFromCache` indicates if the SDK client has emitted the SDK_READY_FROM_CACHE event. - * - `hasTimedout` indicates if the SDK client has emitted the SDK_READY_TIMED_OUT event. - * - `isDestroyed` indicates if the SDK client has been destroyed, i.e., if the `destroySplitSdk` action was dispatched. + * This function is similar to the `selectStatus` selector, but it does not require the Split state as a parameter since it uses the global `splitSdk` object. + * Consider using the `selectStatus` selector instead for a more Redux-friendly approach. * * @param {SplitIO.SplitKey} key To use only on client-side. Ignored in server-side. If a key is provided and a client associated to that key has been used, the status of that client is returned. * If no key is provided, the status of the main client and manager is returned (the main client shares the status with the manager). diff --git a/src/index.ts b/src/index.ts index c99eda8..0aefb73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,10 +2,11 @@ export { splitReducer } from './reducer'; export { initSplitSdk, getTreatments, destroySplitSdk, splitSdk } from './asyncActions'; export { track, getSplitNames, getSplit, getSplits, getStatus } from './helpers'; -export { selectTreatmentValue, selectTreatmentWithConfig, selectTreatmentAndStatus, selectTreatmentWithConfigAndStatus } from './selectors'; +export { selectTreatmentValue, selectTreatmentWithConfig, selectTreatmentAndStatus, selectTreatmentWithConfigAndStatus, selectStatus } from './selectors'; // For React-redux export { connectSplit } from './react-redux/connectSplit'; export { connectToggler, mapTreatmentToProps, mapIsFeatureOnToProps } from './react-redux/connectToggler'; -export { ISplitState } from './types'; +// Types +export { IStatus, ISplitState, IGetSplitState, IInitSplitSdkParams, IGetTreatmentsParams, IDestroySplitSdkParams, ITrackParams } from './types'; diff --git a/src/selectors.ts b/src/selectors.ts index 9b43ed0..ed1411e 100644 --- a/src/selectors.ts +++ b/src/selectors.ts @@ -84,7 +84,18 @@ export function selectTreatmentWithConfigAndStatus(splitState: ISplitState, feat }; } -function selectStatus(splitState: ISplitState, key?: SplitIO.SplitKey): IStatus { +/** + * Extracts an object with the status properties of the SDK client or manager from the Split state. + * + * @param {ISplitState} splitState + * @param {SplitIO.SplitKey} key To use only on client-side. Ignored in server-side. If a key is provided and a client associated to that key has been used, the status of that client is returned. + * If no key is provided, the status of the main client and manager is returned (the main client shares the status with the manager). + * + * @returns {IStatus} The status of the SDK client or manager. + * + * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#subscribe-to-events} + */ +export function selectStatus(splitState: ISplitState, key?: SplitIO.SplitKey): IStatus { const status = splitState ? isMainClient(key) ? splitState : diff --git a/src/types.ts b/src/types.ts index 4a0909d..4b2d6ab 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,7 +4,7 @@ export interface IStatus { /** * isReady indicates if Split client is ready, i.e., if it has emitted an SDK_READY event. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isReady: boolean; @@ -12,21 +12,21 @@ export interface IStatus { * isReadyFromCache indicates if Split client has emitted an SDK_READY_FROM_CACHE event, what means that the SDK is ready to * evaluate using LocalStorage cached data (which might be stale). * This flag only applies for the Browser if using LOCALSTORAGE as storage type. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isReadyFromCache: boolean; /** * isTimedout indicates if the Split client has emitted an SDK_READY_TIMED_OUT event and is not ready. * In other words, `isTimedout` is equivalent to `hasTimeout && !isReady`. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ isTimedout: boolean; /** * hasTimedout indicates if the Split client has ever emitted an SDK_READY_TIMED_OUT event. * It's meant to keep a reference that the SDK emitted a timeout at some point, not the current state. - * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#subscribe-to-events} */ hasTimedout: boolean; @@ -38,7 +38,7 @@ export interface IStatus { /** * lastUpdate is the timestamp of the last Split client event (SDK_READY, SDK_READY_TIMED_OUT or SDK_UPDATE). - * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#advanced-subscribe-to-events-and-changes} + * @see {@link https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK#subscribe-to-events} */ lastUpdate: number; }