Skip to content

Commit 60afbda

Browse files
update how SDK version is overwriten
1 parent d40b442 commit 60afbda

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/SplitFactory.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22

33
import { SplitComponent } from './SplitClient';
44
import { ISplitFactoryProps } from './types';
5-
import { VERSION, WARN_SF_CONFIG_AND_FACTORY, ERROR_SF_NO_CONFIG_AND_FACTORY } from './constants';
5+
import { WARN_SF_CONFIG_AND_FACTORY, ERROR_SF_NO_CONFIG_AND_FACTORY } from './constants';
66
import { getSplitFactory, destroySplitFactory, IFactoryWithClients } from './utils';
77

88
/**
@@ -46,8 +46,6 @@ class SplitFactory extends React.Component<ISplitFactoryProps, { factory: SplitI
4646
factory = propFactory;
4747
} else {
4848
if (config) {
49-
// Don't try this at home. Used to overwrite the settings version when we create our own factory.
50-
(config as any).version = VERSION;
5149
// We use an idempotent variant of the Split factory builder (i.e., given the same config, it returns the same already
5250
// created instance), since React component constructors is part of render-phase and can be invoked multiple times.
5351
factory = getSplitFactory(config);

src/__tests__/testUtils/mockSplitSdk.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function mockClient(_key: SplitIO.SplitKey, _trafficType?: string) {
108108

109109
export function mockSdk() {
110110

111-
return jest.fn((config: SplitIO.IBrowserSettings) => {
111+
return jest.fn((config: SplitIO.IBrowserSettings, __updateModules) => {
112112

113113
// Manager
114114
const names: jest.Mock = jest.fn().mockReturnValue([]);
@@ -134,6 +134,8 @@ export function mockSdk() {
134134
}, config),
135135
};
136136

137+
if (__updateModules) __updateModules(factory);
138+
137139
return factory;
138140
});
139141

src/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { SplitFactory as SplitSdk } from '@splitsoftware/splitio/client';
3+
import { VERSION } from './constants';
34

45
// Utils used to access singleton instances of Split factories and clients, and to gracefully shutdown all clients together.
56

@@ -31,7 +32,10 @@ export const __factories: Map<SplitIO.IBrowserSettings, IFactoryWithClients> = n
3132
export function getSplitFactory(config: SplitIO.IBrowserSettings): IFactoryWithClients {
3233
if (!__factories.has(config)) {
3334
// SplitSDK is not an idempotent operation
34-
const newFactory = SplitSdk(config) as IFactoryWithClients;
35+
// @ts-expect-error. 2nd param is not part of type definitions. Used to overwrite the SDK version
36+
const newFactory = SplitSdk(config, (modules) => {
37+
modules.settings.version = VERSION;
38+
}) as IFactoryWithClients;
3539
newFactory.sharedClientInstances = new Set();
3640
newFactory.config = config;
3741
__factories.set(config, newFactory);

0 commit comments

Comments
 (0)