Skip to content

Commit 267f12b

Browse files
bug: Remove execution context determination (#787)
* Remove execution context handling * Fix bad merge on my part * Match import formatting
1 parent 346f2c0 commit 267f12b

File tree

6 files changed

+8
-77
lines changed

6 files changed

+8
-77
lines changed

packages/optimizely-sdk/lib/index.browser.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import { createNotificationCenter } from './core/notification_center';
3232
import { default as eventProcessor } from './plugins/event_processor';
3333
import { OptimizelyDecideOption, Client, Config } from './shared_types';
3434
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/browser_http_polling_datafile_manager';
35-
import { EXECUTION_CONTEXT_TYPE } from './utils/enums';
36-
import { ExecutionContext } from './utils/execution_context';
3735

3836
const logger = getLogger();
3937
logHelper.setLogHandler(loggerPlugin.createLogger());
@@ -46,8 +44,6 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000;
4644

4745
let hasRetriedEvents = false;
4846

49-
ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.BROWSER;
50-
5147
/**
5248
* Creates an instance of the Optimizely class
5349
* @param {Config} config

packages/optimizely-sdk/lib/index.node.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import { createNotificationCenter } from './core/notification_center';
3232
import { createEventProcessor } from './plugins/event_processor';
3333
import { OptimizelyDecideOption, Client, Config } from './shared_types';
3434
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager';
35-
import { ExecutionContext } from './utils/execution_context';
36-
import { EXECUTION_CONTEXT_TYPE } from './utils/enums';
3735

3836
const logger = getLogger();
3937
setLogLevel(LogLevel.ERROR);
@@ -42,8 +40,6 @@ const DEFAULT_EVENT_BATCH_SIZE = 10;
4240
const DEFAULT_EVENT_FLUSH_INTERVAL = 30000; // Unit is ms, default is 30s
4341
const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000;
4442

45-
ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.NODE;
46-
4743
/**
4844
* Creates an instance of the Optimizely class
4945
* @param {Config} config

packages/optimizely-sdk/lib/index.react_native.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ import eventProcessorConfigValidator from './utils/event_processor_config_valida
3131
import { createNotificationCenter } from './core/notification_center';
3232
import { createEventProcessor } from './plugins/event_processor/index.react_native';
3333
import { OptimizelyDecideOption, Client, Config } from './shared_types';
34-
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/react_native_http_polling_datafile_manager';
35-
import { EXECUTION_CONTEXT_TYPE } from './utils/enums';
36-
import { ExecutionContext } from './utils/execution_context';
34+
import { createHttpPollingDatafileManager } from
35+
'./plugins/datafile_manager/react_native_http_polling_datafile_manager';
3736

3837
const logger = getLogger();
3938
setLogHandler(loggerPlugin.createLogger());
@@ -43,8 +42,6 @@ const DEFAULT_EVENT_BATCH_SIZE = 10;
4342
const DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
4443
const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000;
4544

46-
ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.BROWSER;
47-
4845
/**
4946
* Creates an instance of the Optimizely class
5047
* @param {Config} config

packages/optimizely-sdk/lib/utils/enums/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,3 @@ export enum NOTIFICATION_TYPES {
291291
OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE',
292292
TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event',
293293
}
294-
295-
296-
/**
297-
* Valid types of Javascript contexts in which this code is executing
298-
*/
299-
export enum EXECUTION_CONTEXT_TYPE {
300-
NOT_DEFINED,
301-
BROWSER,
302-
NODE,
303-
}

packages/optimizely-sdk/lib/utils/execution_context/index.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/optimizely-sdk/lib/utils/http_request_handler/request_handler_factory.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@ import { LogHandler } from '../../modules/logging';
1818
import { RequestHandler } from './http';
1919
import { NodeRequestHandler } from './node_request_handler';
2020
import { BrowserRequestHandler } from './browser_request_handler';
21-
import { ExecutionContext } from '../execution_context';
22-
import { EXECUTION_CONTEXT_TYPE } from '../enums';
2321

2422
/**
2523
* Factory to create the appropriate type of RequestHandler based on a provided context
2624
*/
2725
export class RequestHandlerFactory {
2826
public static createHandler(logger: LogHandler, timeout?: number): RequestHandler {
29-
switch (ExecutionContext.Current) {
30-
case EXECUTION_CONTEXT_TYPE.BROWSER:
31-
return new BrowserRequestHandler(logger, timeout);
32-
case EXECUTION_CONTEXT_TYPE.NODE:
33-
return new NodeRequestHandler(logger, timeout);
34-
default:
35-
return null as unknown as RequestHandler;
27+
if (window) {
28+
return new BrowserRequestHandler(logger, timeout);
29+
} else if (process) {
30+
return new NodeRequestHandler(logger, timeout);
31+
} else {
32+
return null as unknown as RequestHandler;
3633
}
3734
}
3835
}

0 commit comments

Comments
 (0)