Skip to content

Commit 0eb0ee2

Browse files
author
Matt Carroll
committed
Add createEventProcessor factory function
1 parent 4e6b706 commit 0eb0ee2

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { LogTierV1EventProcessor, LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-processor';
2+
3+
export function createEventProcessor(
4+
...args: ConstructorParameters<typeof LogTierV1EventProcessor>
5+
): LogTierV1EventProcessor {
6+
return new LogTierV1EventProcessor(...args);
7+
}
8+
9+
export { EventProcessor, LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-processor';
10+
11+
export default { createEventProcessor, LocalStoragePendingEventsDispatcher };

packages/optimizely-sdk/lib/index.browser.tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
1818
import * as logging from '@optimizely/js-sdk-logging';
19-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
19+
import eventProcessor from './core/event_processor';
2020

2121
import Optimizely from './optimizely';
2222
import testData from './tests/test_data';
@@ -391,11 +391,11 @@ describe('javascript-sdk', function() {
391391
describe('event processor configuration', function() {
392392
var eventProcessorSpy;
393393
beforeEach(function() {
394-
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
394+
eventProcessorSpy = sinon.spy(eventProcessor, 'createEventProcessor');
395395
});
396396

397397
afterEach(function() {
398-
eventProcessor.LogTierV1EventProcessor.restore();
398+
eventProcessor.createEventProcessor.restore();
399399
});
400400

401401
it('should use default event flush interval when none is provided', function() {

packages/optimizely-sdk/lib/index.node.tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
18-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
18+
import eventProcessor from './core/event_processor';
1919

2020
import * as enums from './utils/enums';
2121
import Optimizely from './optimizely';
@@ -96,11 +96,11 @@ describe('optimizelyFactory', function() {
9696
describe('event processor configuration', function() {
9797
var eventProcessorSpy;
9898
beforeEach(function() {
99-
eventProcessorSpy = sinon.stub(eventProcessor, 'LogTierV1EventProcessor').callThrough();
99+
eventProcessorSpy = sinon.stub(eventProcessor, 'createEventProcessor').callThrough();
100100
});
101101

102102
afterEach(function() {
103-
eventProcessor.LogTierV1EventProcessor.restore();
103+
eventProcessor.createEventProcessor.restore();
104104
});
105105

106106
it('should ignore invalid event flush interval and use default instead', function() {

packages/optimizely-sdk/lib/index.react_native.tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
1818
import * as logging from '@optimizely/js-sdk-logging';
19-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
19+
import eventProcessor from './core/event_processor';
2020

2121
import Optimizely from './optimizely';
2222
import testData from './tests/test_data';
@@ -184,11 +184,11 @@ describe('javascript-sdk/react-native', function() {
184184
describe('event processor configuration', function() {
185185
var eventProcessorSpy;
186186
beforeEach(function() {
187-
eventProcessorSpy = sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
187+
eventProcessorSpy = sinon.spy(eventProcessor, 'createEventProcessor');
188188
});
189189

190190
afterEach(function() {
191-
eventProcessor.LogTierV1EventProcessor.restore();
191+
eventProcessor.createEventProcessor.restore();
192192
});
193193

194194
it('should use default event flush interval when none is provided', function() {

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
1818
import { sprintf } from '@optimizely/js-sdk-utils';
19-
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
19+
import eventProcessor from '../core/event_processor';
2020
import * as logging from '@optimizely/js-sdk-logging';
2121

2222
import Optimizely from './';
@@ -7730,11 +7730,11 @@ describe('lib/optimizely', function() {
77307730
start: sinon.stub(),
77317731
stop: sinon.stub(),
77327732
};
7733-
sinon.stub(eventProcessor, 'LogTierV1EventProcessor').returns(mockEventProcessor);
7733+
sinon.stub(eventProcessor, 'createEventProcessor').returns(mockEventProcessor);
77347734
});
77357735

77367736
afterEach(function() {
7737-
eventProcessor.LogTierV1EventProcessor.restore();
7737+
eventProcessor.createEventProcessor.restore();
77387738
});
77397739

77407740
describe('when the event processor stop method returns a promise that fulfills', function() {
@@ -7813,13 +7813,13 @@ describe('lib/optimizely', function() {
78137813
beforeEach(function() {
78147814
sinon.stub(errorHandler, 'handleError');
78157815
sinon.stub(createdLogger, 'log');
7816-
sinon.spy(eventProcessor, 'LogTierV1EventProcessor');
7816+
sinon.spy(eventProcessor, 'createEventProcessor');
78177817
});
78187818

78197819
afterEach(function() {
78207820
errorHandler.handleError.restore();
78217821
createdLogger.log.restore();
7822-
eventProcessor.LogTierV1EventProcessor.restore();
7822+
eventProcessor.createEventProcessor.restore();
78237823
});
78247824

78257825
it('should instantiate the eventProcessor with the provided event flush interval and event batch size', function() {
@@ -7836,7 +7836,7 @@ describe('lib/optimizely', function() {
78367836
});
78377837

78387838
sinon.assert.calledWithExactly(
7839-
eventProcessor.LogTierV1EventProcessor,
7839+
eventProcessor.createEventProcessor,
78407840
sinon.match({
78417841
dispatcher: eventDispatcher,
78427842
flushInterval: 20000,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { getImpressionEvent, getConversionEvent } from '../core/event_builder';
3333
import { buildImpressionEvent, buildConversionEvent } from '../core/event_builder/event_helpers';
3434
import fns from '../utils/fns'
3535
import { validate } from '../utils/attributes_validator';
36-
import { EventProcessor, LogTierV1EventProcessor } from '@optimizely/js-sdk-event-processor';
36+
import { EventProcessor, default as eventProcessor } from '../core/event_processor';
3737
import * as enums from '../utils/enums';
3838
import * as eventTagsValidator from '../utils/event_tags_validator';
3939
import * as projectConfig from '../core/project_config';
@@ -170,7 +170,7 @@ export default class Optimizely {
170170
notificationCenter: this.notificationCenter,
171171
}
172172

173-
this.eventProcessor = new LogTierV1EventProcessor(eventProcessorConfig);
173+
this.eventProcessor = eventProcessor.createEventProcessor(eventProcessorConfig);
174174

175175
const eventProcessorStartedPromise = this.eventProcessor.start();
176176

0 commit comments

Comments
 (0)