-
Notifications
You must be signed in to change notification settings - Fork 81
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
Dont use pendingEventsDispatcher with user defined eventDispatcher #289
Dont use pendingEventsDispatcher with user defined eventDispatcher #289
Conversation
2 similar comments
9d1d9de
to
1ed3859
Compare
}); | ||
|
||
describe('when an eventDispatcher is passed in', function() { | ||
it('should wrap the default eventDispatcher and invoke sendPendingEvents', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should say 'should not wrap...' right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
if (config.eventDispatcher == null) { // eslint-disable-line eqeqeq | ||
// only wrap the event dispatcher with pending events retry if the user didnt override | ||
eventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({ | ||
eventDispatcher: defaultEventDispatcher, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we we no longer allow a custom eventDispatcher
to be used with LocalStoragePendingEventsDispatcher
, does passing eventDispatcher
to LocalStoragePendingEventsDispatcher
still make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, you mean the idea of having an event dispatcher that wraps another event dispatcher.
Probably isn't the most ideal design, but I dont hate it. If we just made this the default event dispatcher, without wrapping it, then we'd be replacing the existing defaultEventDispatcher
implementation. That could be a bit strange for people using the eventDispatcher in a custom manner.
When we made the decision to only wrap the defaultEventDispatcher, I did feel a bit safer about this pattern then replacement.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me. Initially, I thought this wrapper pattern was weird given that it only ever wraps one thing, but it is safe, and I like that pending-events-related logic is isolated.
9744b09
to
9a351c0
Compare
9a351c0
to
e25f922
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
Summary
The is an edge case where the
sendPendingEvents()
mechanism keeps sending events because a custom eventDispatcher never invoked thecallback()
denoting the request completed. This leads to events piling up in localStorage and sending every event each time the SDK is initialized.To prevent this only use the pendingEventDispatcher if the default event dispatcher is used, since this guarantees the callback is properly called.
Test plan
Issues