Skip to content

fix: Use default event dispatcher in React Native entry point when none provided by user #383

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 2 commits into from
Dec 30, 2019
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
5 changes: 3 additions & 2 deletions packages/optimizely-sdk/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
Changes that have landed but are not yet released.
### Bug fixes
- Fixed default event dispatcher not used in React Native entry point ([#383](https://github.com/optimizely/javascript-sdk/pull/383))

## [3.4.0-beta] - December 18th, 2019
### Bug fixes
Expand All @@ -14,7 +15,7 @@ Changes that have landed but are not yet released.
### New Features

- Added a new API to get a project configuration static data.
- Call `getOptimizelyConfig()` to get a snapshot copy of project configuration static data.
- Call `getOptimizelyConfig()` to get a snapshot copy of project configuration static data.
- It returns an `OptimizelyConfig` instance which includes a datafile revision number, all experiments, and feature flags mapped by their key values.
- For details, refer to a documention page: https://docs.developers.optimizely.com/full-stack/docs/optimizelyconfig-javascript-node

Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/index.react_native.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ module.exports = {
{
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,
eventDispatcher: defaultEventDispatcher,
eventFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
},
config,
{
eventDispatcher: config.eventDispatcher,
// always get the OptimizelyLogger facade from logging
logger: logger,
errorHandler: logging.getErrorHandler(),
Expand Down
25 changes: 25 additions & 0 deletions packages/optimizely-sdk/lib/index.react_native.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var packageJSON = require('../package.json');
var testData = require('./tests/test_data');
var eventProcessor = require('@optimizely/js-sdk-event-processor');
var eventProcessorConfigValidator = require('./utils/event_processor_config_validator');
var defaultEventDispatcher = require('./plugins/event_dispatcher/index.browser');

var chai = require('chai');
var assert = chai.assert;
Expand Down Expand Up @@ -131,6 +132,30 @@ describe('javascript-sdk/react-native', function() {
assert.strictEqual(activate, 'control');
});

describe('when no event dispatcher passed to createInstance', function() {
beforeEach(function() {
sinon.stub(defaultEventDispatcher, 'dispatchEvent', function(evt, cb) {
cb();
});
})

afterEach(function() {
defaultEventDispatcher.dispatchEvent.restore();
});

it('uses the default event dispatcher', function() {
var optlyInstance = optimizelyFactory.createInstance({
datafile: testData.getTestProjectConfig(),
errorHandler: fakeErrorHandler,
logger: silentLogger,
});
optlyInstance.activate('testExperiment', 'testUser');
return optlyInstance.close().then(function() {
sinon.assert.calledOnce(defaultEventDispatcher.dispatchEvent);
});
});
});

describe('when passing in logLevel', function() {
beforeEach(function() {
sinon.stub(logging, 'setLogLevel');
Expand Down