@@ -9,19 +9,15 @@ import { objectAssign } from '../utils/lang/objectAssign';
99import { RETRIEVE_CLIENT_DEFAULT , NEW_SHARED_CLIENT , RETRIEVE_CLIENT_EXISTING , LOG_PREFIX_CLIENT_INSTANTIATION } from '../logger/constants' ;
1010import { SDK_SEGMENTS_ARRIVED } from '../readiness/constants' ;
1111import { ISdkFactoryContext } from '../sdkFactory/types' ;
12-
13- function buildInstanceId ( key : SplitIO . SplitKey , trafficType ?: string ) {
14- // @ts -ignore
15- return `${ key . matchingKey ? key . matchingKey : key } -${ key . bucketingKey ? key . bucketingKey : key } -${ trafficType !== undefined ? trafficType : '' } ` ;
16- }
12+ import { buildInstanceId } from './identity' ;
1713
1814/**
1915 * Factory of client method for the client-side (browser) variant of the Isomorphic JS SDK,
2016 * where clients can have a bound TT for the track method, which is provided via the settings
2117 * (default client) or the client method (shared clients).
2218 */
2319export function sdkClientMethodCSFactory ( params : ISdkFactoryContext ) : ( key ?: SplitIO . SplitKey , trafficType ?: string ) => SplitIO . ICsClient {
24- const { storage, syncManager, sdkReadinessManager, settings : { core : { key, trafficType } , startup : { readyTimeout } , log } } = params ;
20+ const { clients , storage, syncManager, sdkReadinessManager, settings : { core : { key, trafficType } , startup : { readyTimeout } , log } } = params ;
2521
2622 const mainClientInstance = clientCSDecorator (
2723 log ,
@@ -34,8 +30,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
3430 const defaultInstanceId = buildInstanceId ( parsedDefaultKey , trafficType ) ;
3531
3632 // Cache instances created per factory.
37- const clientInstances : Record < string , SplitIO . ICsClient > = { } ;
38- clientInstances [ defaultInstanceId ] = mainClientInstance ;
33+ clients [ defaultInstanceId ] = mainClientInstance ;
3934
4035 return function client ( key ?: SplitIO . SplitKey , trafficType ?: string ) {
4136 if ( key === undefined ) {
@@ -58,7 +53,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
5853 }
5954 const instanceId = buildInstanceId ( validKey , validTrafficType ) ;
6055
61- if ( ! clientInstances [ instanceId ] ) {
56+ if ( ! clients [ instanceId ] ) {
6257 const matchingKey = getMatching ( validKey ) ;
6358
6459 const sharedSdkReadiness = sdkReadinessManager . shared ( readyTimeout ) ;
@@ -80,7 +75,7 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
8075
8176 // As shared clients reuse all the storage information, we don't need to check here if we
8277 // will use offline or online mode. We should stick with the original decision.
83- clientInstances [ instanceId ] = clientCSDecorator (
78+ clients [ instanceId ] = clientCSDecorator (
8479 log ,
8580 sdkClientFactory ( objectAssign ( { } , params , {
8681 sdkReadinessManager : sharedSdkReadiness ,
@@ -99,6 +94,6 @@ export function sdkClientMethodCSFactory(params: ISdkFactoryContext): (key?: Spl
9994 log . debug ( RETRIEVE_CLIENT_EXISTING ) ;
10095 }
10196
102- return clientInstances [ instanceId ] ;
97+ return clients [ instanceId ] ;
10398 } ;
10499}
0 commit comments