Skip to content

Commit

Permalink
Merge pull request #120 from splitio/release_v1.15.0
Browse files Browse the repository at this point in the history
Upgrade JS SDK v10.29.0: large segments and factory `destroy` method
  • Loading branch information
EmilianoSanchez authored Oct 29, 2024
2 parents 844eec5 + 14f5134 commit 60210fe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"homepage": "https://github.com/splitio/redux-client#readme",
"dependencies": {
"@splitsoftware/splitio": "10.28.0",
"@splitsoftware/splitio": "10.28.1-rc.2",
"tslib": "^2.3.1"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/utils/mockBrowserSplitSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,19 @@ export function mockSdk() {
return __clients__[instanceId] || (__clients__[instanceId] = mockClient(key));
});

// Factory destroy
const destroy = jest.fn(() => {
return Promise.all(Object.keys(__clients__).map(instanceId => __clients__[instanceId].destroy()));
});

const modules = { settings: { version: 'javascript-10.18.0' } };
if (__updateModules) __updateModules(modules);

// SDK factory
const factory = {
client,
manager,
destroy,
settings: modules.settings,
__names__: names,
__split__: split,
Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/utils/mockNodeSplitSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,19 @@ export function mockSdk() {
return __client__;
});

// Factory destroy
const destroy = jest.fn(() => {
return __client__.destroy();
});

const modules = { settings: { version: 'nodejs-10.18.0' } };
if (__updateModules) __updateModules(modules);

// SDK factory
const factory = {
client,
manager,
destroy,
settings: modules.settings,
__names__: names,
__split__: split,
Expand Down
9 changes: 3 additions & 6 deletions src/asyncActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,20 @@ export function destroySplitSdk(params: IDestroySplitSdkParams = {}): (dispatch:
// Destroy the client(s) outside the thunk action, since on server-side the action is not dispatched
// because stores have a life-span per session/request and there may not be one when server shuts down.
const mainClient = splitSdk.factory.client();
// in node, `splitSdk.sharedClients` is an empty object
const sharedClients = splitSdk.sharedClients;
const destroyPromises = Object.keys(sharedClients).map((clientKey) => sharedClients[clientKey].destroy());
destroyPromises.push(mainClient.destroy());
const destroyPromise = splitSdk.factory.destroy();

// Add onDestroy callback listener. It is important for server-side, where the thunk action is not dispatched
// and so the user cannot access the promise as follows: `store.dispatch(destroySplitSdk()).then(...)`
let dispatched = false;
if (params.onDestroy) Promise.all(destroyPromises).then(() => {
if (params.onDestroy) destroyPromise.then(() => {
// condition to avoid calling the callback twice, since it should be called preferably after the action has been dispatched
if (!dispatched) params.onDestroy();
});

// Return Thunk (async) action
return (dispatch: Dispatch<Action>): Promise<void> => {
dispatched = true;
return Promise.all(destroyPromises).then(function () {
return destroyPromise.then(function () {
dispatch(splitDestroy(__getStatus(mainClient).lastUpdate));
if (params.onDestroy) params.onDestroy();
});
Expand Down

0 comments on commit 60210fe

Please sign in to comment.