Skip to content

feat: Added React Native Client Engines to be sent in events #696

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 1 commit into from
Aug 2, 2021
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
8 changes: 4 additions & 4 deletions packages/optimizely-sdk/lib/index.react_native.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('javascript-sdk/react-native', function() {
assert.equal(optlyInstance.clientVersion, '4.6.2');
});

it('should set the Javascript client engine and version', function() {
it('should set the React Native JS client engine and javascript SDK version', function() {
var optlyInstance = optimizelyFactory.createInstance({
datafile: {},
errorHandler: fakeErrorHandler,
Expand All @@ -101,11 +101,11 @@ describe('javascript-sdk/react-native', function() {
});
// Invalid datafile causes onReady Promise rejection - catch this error
optlyInstance.onReady().catch(function() {});
assert.equal('javascript-sdk', optlyInstance.clientEngine);
assert.equal('react-native-js-sdk', optlyInstance.clientEngine);
assert.equal(packageJSON.version, optlyInstance.clientVersion);
});

it('should allow passing of "react-sdk" as the clientEngine', function() {
it('should allow passing of "react-sdk" as the clientEngine and convert it to "react-native-sdk"', function() {
var optlyInstance = optimizelyFactory.createInstance({
clientEngine: 'react-sdk',
datafile: {},
Expand All @@ -115,7 +115,7 @@ describe('javascript-sdk/react-native', function() {
});
// Invalid datafile causes onReady Promise rejection - catch this error
optlyInstance.onReady().catch(function() {});
assert.equal('react-sdk', optlyInstance.clientEngine);
assert.equal('react-native-sdk', optlyInstance.clientEngine);
});

it('should activate with provided event dispatcher', function() {
Expand Down
7 changes: 6 additions & 1 deletion packages/optimizely-sdk/lib/index.react_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const createInstance = function(config: SDKOptions): Optimizely | null {
}

const optimizelyOptions = {
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
clientEngine: enums.REACT_NATIVE_JS_CLIENT_ENGINE,
eventDispatcher: defaultEventDispatcher,
eventMaxQueueSize: DEFAULT_EVENT_MAX_QUEUE_SIZE,
...config,
Expand All @@ -94,6 +94,11 @@ const createInstance = function(config: SDKOptions): Optimizely | null {
errorHandler: getErrorHandler()
};

// If client engine is react, convert it to react native.
if (optimizelyOptions.clientEngine === enums.REACT_CLIENT_ENGINE) {
optimizelyOptions.clientEngine = enums.REACT_NATIVE_CLIENT_ENGINE;
}

return new Optimizely(optimizelyOptions);
} catch (e) {
logger.error(e);
Expand Down
4 changes: 4 additions & 0 deletions packages/optimizely-sdk/lib/utils/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,16 @@ export const CONTROL_ATTRIBUTES = {
export const JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
export const NODE_CLIENT_ENGINE = 'node-sdk';
export const REACT_CLIENT_ENGINE = 'react-sdk';
export const REACT_NATIVE_CLIENT_ENGINE = 'react-native-sdk';
export const REACT_NATIVE_JS_CLIENT_ENGINE = 'react-native-js-sdk';
export const NODE_CLIENT_VERSION = '4.6.2';

export const VALID_CLIENT_ENGINES = [
NODE_CLIENT_ENGINE,
REACT_CLIENT_ENGINE,
JAVASCRIPT_CLIENT_ENGINE,
REACT_NATIVE_CLIENT_ENGINE,
REACT_NATIVE_JS_CLIENT_ENGINE,
];

export const NOTIFICATION_TYPES = notificationTypesEnum;
Expand Down