diff --git a/packages/optimizely-sdk/lib/index.browser.ts b/packages/optimizely-sdk/lib/index.browser.ts index ca613401c..1c8cf4068 100644 --- a/packages/optimizely-sdk/lib/index.browser.ts +++ b/packages/optimizely-sdk/lib/index.browser.ts @@ -32,8 +32,6 @@ import { createNotificationCenter } from './core/notification_center'; import { default as eventProcessor } from './plugins/event_processor'; import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/browser_http_polling_datafile_manager'; -import { EXECUTION_CONTEXT_TYPE } from './utils/enums'; -import { ExecutionContext } from './utils/execution_context'; const logger = getLogger(); logHelper.setLogHandler(loggerPlugin.createLogger()); @@ -46,8 +44,6 @@ const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; let hasRetriedEvents = false; -ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.BROWSER; - /** * Creates an instance of the Optimizely class * @param {Config} config diff --git a/packages/optimizely-sdk/lib/index.node.ts b/packages/optimizely-sdk/lib/index.node.ts index 6fe59eb22..56ba69c71 100644 --- a/packages/optimizely-sdk/lib/index.node.ts +++ b/packages/optimizely-sdk/lib/index.node.ts @@ -32,8 +32,6 @@ import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor'; import { OptimizelyDecideOption, Client, Config } from './shared_types'; import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager'; -import { ExecutionContext } from './utils/execution_context'; -import { EXECUTION_CONTEXT_TYPE } from './utils/enums'; const logger = getLogger(); setLogLevel(LogLevel.ERROR); @@ -42,8 +40,6 @@ const DEFAULT_EVENT_BATCH_SIZE = 10; const DEFAULT_EVENT_FLUSH_INTERVAL = 30000; // Unit is ms, default is 30s const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; -ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.NODE; - /** * Creates an instance of the Optimizely class * @param {Config} config diff --git a/packages/optimizely-sdk/lib/index.react_native.ts b/packages/optimizely-sdk/lib/index.react_native.ts index 82d77b85f..31dd92d45 100644 --- a/packages/optimizely-sdk/lib/index.react_native.ts +++ b/packages/optimizely-sdk/lib/index.react_native.ts @@ -31,9 +31,8 @@ import eventProcessorConfigValidator from './utils/event_processor_config_valida import { createNotificationCenter } from './core/notification_center'; import { createEventProcessor } from './plugins/event_processor/index.react_native'; import { OptimizelyDecideOption, Client, Config } from './shared_types'; -import { createHttpPollingDatafileManager } from './plugins/datafile_manager/react_native_http_polling_datafile_manager'; -import { EXECUTION_CONTEXT_TYPE } from './utils/enums'; -import { ExecutionContext } from './utils/execution_context'; +import { createHttpPollingDatafileManager } from + './plugins/datafile_manager/react_native_http_polling_datafile_manager'; const logger = getLogger(); setLogHandler(loggerPlugin.createLogger()); @@ -43,8 +42,6 @@ const DEFAULT_EVENT_BATCH_SIZE = 10; const DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s const DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000; -ExecutionContext.Current = EXECUTION_CONTEXT_TYPE.BROWSER; - /** * Creates an instance of the Optimizely class * @param {Config} config diff --git a/packages/optimizely-sdk/lib/utils/enums/index.ts b/packages/optimizely-sdk/lib/utils/enums/index.ts index e9eecdcf4..5db60a894 100644 --- a/packages/optimizely-sdk/lib/utils/enums/index.ts +++ b/packages/optimizely-sdk/lib/utils/enums/index.ts @@ -291,13 +291,3 @@ export enum NOTIFICATION_TYPES { OPTIMIZELY_CONFIG_UPDATE = 'OPTIMIZELY_CONFIG_UPDATE', TRACK = 'TRACK:event_key, user_id, attributes, event_tags, event', } - - -/** - * Valid types of Javascript contexts in which this code is executing - */ -export enum EXECUTION_CONTEXT_TYPE { - NOT_DEFINED, - BROWSER, - NODE, -} diff --git a/packages/optimizely-sdk/lib/utils/execution_context/index.ts b/packages/optimizely-sdk/lib/utils/execution_context/index.ts deleted file mode 100644 index f9f3e2457..000000000 --- a/packages/optimizely-sdk/lib/utils/execution_context/index.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2022, Optimizely - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { EXECUTION_CONTEXT_TYPE } from '../enums'; - -/** - * Determine the running or execution context for JavaScript - * Note: React Native is considered a browser context - */ -export class ExecutionContext { - /** - * Holds the current value of the execution context - * @private - */ - private static _currentContext: EXECUTION_CONTEXT_TYPE = EXECUTION_CONTEXT_TYPE.NOT_DEFINED; - - /** - * Gets the current running context - * @constructor - */ - public static get Current(): EXECUTION_CONTEXT_TYPE { - return this._currentContext; - } - - /** - * Sets the current running context ideally from package initialization - * @param newValue The new execution context - * @constructor - */ - public static set Current(newValue: EXECUTION_CONTEXT_TYPE) { - this._currentContext = newValue; - } -} diff --git a/packages/optimizely-sdk/lib/utils/http_request_handler/request_handler_factory.ts b/packages/optimizely-sdk/lib/utils/http_request_handler/request_handler_factory.ts index 455754cb5..ddab23faf 100644 --- a/packages/optimizely-sdk/lib/utils/http_request_handler/request_handler_factory.ts +++ b/packages/optimizely-sdk/lib/utils/http_request_handler/request_handler_factory.ts @@ -18,21 +18,18 @@ import { LogHandler } from '../../modules/logging'; import { RequestHandler } from './http'; import { NodeRequestHandler } from './node_request_handler'; import { BrowserRequestHandler } from './browser_request_handler'; -import { ExecutionContext } from '../execution_context'; -import { EXECUTION_CONTEXT_TYPE } from '../enums'; /** * Factory to create the appropriate type of RequestHandler based on a provided context */ export class RequestHandlerFactory { public static createHandler(logger: LogHandler, timeout?: number): RequestHandler { - switch (ExecutionContext.Current) { - case EXECUTION_CONTEXT_TYPE.BROWSER: - return new BrowserRequestHandler(logger, timeout); - case EXECUTION_CONTEXT_TYPE.NODE: - return new NodeRequestHandler(logger, timeout); - default: - return null as unknown as RequestHandler; + if (window) { + return new BrowserRequestHandler(logger, timeout); + } else if (process) { + return new NodeRequestHandler(logger, timeout); + } else { + return null as unknown as RequestHandler; } } }