Skip to content

bug: Remove execution context determination #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/optimizely-sdk/lib/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions packages/optimizely-sdk/lib/index.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions packages/optimizely-sdk/lib/index.react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions packages/optimizely-sdk/lib/utils/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
45 changes: 0 additions & 45 deletions packages/optimizely-sdk/lib/utils/execution_context/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +27 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get removed by #786

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the whole file will...

}
}
}