Skip to content

Commit b1e4596

Browse files
authored
feat: Integrate react native event processor with optimizely SDK (#532)
Summary: Integrated the newly released event processor package which implements react native event processor to support offline storage of events. Test plan: All Unit tests should pass All FSC tests should pass
1 parent 86d13bd commit b1e4596

File tree

9 files changed

+28
-19
lines changed

9 files changed

+28
-19
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ describe('javascript-sdk', function() {
475475
sinon.assert.calledWithExactly(
476476
eventProcessorSpy,
477477
sinon.match({
478-
maxQueueSize: 10,
478+
batchSize: 10,
479479
})
480480
);
481481
});
@@ -500,7 +500,7 @@ describe('javascript-sdk', function() {
500500
sinon.assert.calledWithExactly(
501501
eventProcessorSpy,
502502
sinon.match({
503-
maxQueueSize: 10,
503+
batchSize: 10,
504504
})
505505
);
506506
});
@@ -526,7 +526,7 @@ describe('javascript-sdk', function() {
526526
sinon.assert.calledWithExactly(
527527
eventProcessorSpy,
528528
sinon.match({
529-
maxQueueSize: 300,
529+
batchSize: 300,
530530
})
531531
);
532532
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('optimizelyFactory', function() {
161161
sinon.assert.calledWithExactly(
162162
eventProcessorSpy,
163163
sinon.match({
164-
maxQueueSize: 10,
164+
batchSize: 10,
165165
})
166166
);
167167
});
@@ -176,7 +176,7 @@ describe('optimizelyFactory', function() {
176176
sinon.assert.calledWithExactly(
177177
eventProcessorSpy,
178178
sinon.match({
179-
maxQueueSize: 10,
179+
batchSize: 10,
180180
})
181181
);
182182
});
@@ -192,7 +192,7 @@ describe('optimizelyFactory', function() {
192192
sinon.assert.calledWithExactly(
193193
eventProcessorSpy,
194194
sinon.match({
195-
maxQueueSize: 300,
195+
batchSize: 300,
196196
})
197197
);
198198
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ setLogLevel(LogLevel.INFO);
3737

3838
var DEFAULT_EVENT_BATCH_SIZE = 10;
3939
var DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
40+
var DEFAULT_EVENT_MAX_QUEUE_SIZE = 10000;
4041

4142
/**
4243
* Creates an instance of the Optimizely class
@@ -81,6 +82,7 @@ var createInstance = function(config) {
8182
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
8283
eventBatchSize: DEFAULT_EVENT_BATCH_SIZE,
8384
eventDispatcher: defaultEventDispatcher,
85+
eventMaxQueueSize: DEFAULT_EVENT_MAX_QUEUE_SIZE,
8486
eventFlushInterval: DEFAULT_EVENT_FLUSH_INTERVAL,
8587
},
8688
config,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('javascript-sdk/react-native', function() {
268268
sinon.assert.calledWithExactly(
269269
eventProcessorSpy,
270270
sinon.match({
271-
maxQueueSize: 10,
271+
batchSize: 10,
272272
})
273273
);
274274
});
@@ -293,7 +293,7 @@ describe('javascript-sdk/react-native', function() {
293293
sinon.assert.calledWithExactly(
294294
eventProcessorSpy,
295295
sinon.match({
296-
maxQueueSize: 10,
296+
batchSize: 10,
297297
})
298298
);
299299
});
@@ -319,7 +319,7 @@ describe('javascript-sdk/react-native', function() {
319319
sinon.assert.calledWithExactly(
320320
eventProcessorSpy,
321321
sinon.match({
322-
maxQueueSize: 300,
322+
batchSize: 300,
323323
})
324324
);
325325
});

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function Optimizely(config) {
8787
}.bind(this)
8888
);
8989

90-
this.__readyPromise = this.projectConfigManager.onReady();
90+
var projectConfigManagerReadyPromise = this.projectConfigManager.onReady();
9191

9292
var userProfileService = null;
9393
if (config.userProfileService) {
@@ -115,10 +115,17 @@ function Optimizely(config) {
115115
this.eventProcessor = new eventProcessor.LogTierV1EventProcessor({
116116
dispatcher: this.eventDispatcher,
117117
flushInterval: config.eventFlushInterval,
118-
maxQueueSize: config.eventBatchSize,
118+
batchSize: config.eventBatchSize,
119+
maxQueueSize: config.eventMaxQueueSize,
119120
notificationCenter: this.notificationCenter,
120121
});
121-
this.eventProcessor.start();
122+
123+
var eventProcessorStartedPromise = this.eventProcessor.start();
124+
125+
this.__readyPromise = Promise.all([projectConfigManagerReadyPromise, eventProcessorStartedPromise]).then(function(promiseResults) {
126+
// Only return status from project config promise because event processor promise does not return any status.
127+
return promiseResults[0];
128+
})
122129

123130
this.__readyTimeouts = {};
124131
this.__nextReadyTimeoutId = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7682,7 +7682,7 @@ describe('lib/optimizely', function() {
76827682
sinon.match({
76837683
dispatcher: eventDispatcher,
76847684
flushInterval: 20000,
7685-
maxQueueSize: 100,
7685+
batchSize: 100,
76867686
})
76877687
);
76887688
});

packages/optimizely-sdk/lib/plugins/event_dispatcher/index.browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export var dispatchEvent = function(eventObj, callback) {
3434
req.onreadystatechange = function() {
3535
if (req.readyState === READYSTATE_COMPLETE && callback && typeof callback === 'function') {
3636
try {
37-
callback(params);
37+
callback({ statusCode: req.status });
3838
} catch (e) {
3939
// TODO: Log this somehow (consider adding a logger to the EventDispatcher interface)
4040
}

packages/optimizely-sdk/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/optimizely-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"homepage": "https://github.com/optimizely/javascript-sdk/tree/master/packages/optimizely-sdk",
4343
"dependencies": {
4444
"@optimizely/js-sdk-datafile-manager": "^0.6.0",
45-
"@optimizely/js-sdk-event-processor": "^0.4.0",
45+
"@optimizely/js-sdk-event-processor": "^0.5.1",
4646
"@optimizely/js-sdk-logging": "^0.1.0",
4747
"@optimizely/js-sdk-utils": "^0.2.0",
4848
"json-schema": "^0.2.3",

0 commit comments

Comments
 (0)