Skip to content
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

feat: Add public API for setting event dispatcher #139

Merged
merged 8 commits into from
Nov 26, 2024

Conversation

felipecsl
Copy link
Member

Fixes: FF-3604

Motivation and Context

Description

This change accomplishes mainly 2 things:

  • Provide a public API so that consumers of this library can set an instance of EventDispatcher into the EppoClient
  • Provide default config values for DefaultEventDispatcher instance via factory function
  • Parse ingestion URL out of SDK key and set it into the config

How has this been tested?

Wrote tests

// noinspection JSUnusedGlobalSymbols
setEventDispatcher(eventDispatcher: EventDispatcher) {
this.eventDispatcher = eventDispatcher;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really don't love these mutable setter APIs we have in the EppoClient, as a fan of immutable data types, i'd much rather do it like that, but I'm following the existing pattern here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, anything that won't toggle after instantion should be constructor options and immutable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be a bigger refactoring, so maybe we can consider for a future major release

Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me although you've really pissed off the linter 😝

// noinspection JSUnusedGlobalSymbols
setEventDispatcher(eventDispatcher: EventDispatcher) {
this.eventDispatcher = eventDispatcher;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, anything that won't toggle after instantion should be constructor options and immutable

return this.queue.length === 0;
}

[Symbol.iterator](): IterableIterator<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your ruby is bleeding into typescript 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol this is actually part of the standard typescript API :) maybe they were inspired by ruby 🤣

@@ -198,4 +201,26 @@ describe('DefaultEventDispatcher', () => {
expect(global.fetch).toHaveBeenCalled();
});
});

describe('newDefaultEventDispatcher', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Comment on lines +112 to +124
if (!config.ingestionUrl) {
throw new Error('Missing required ingestionUrl in EventDispatcherConfig');
}
if (!config.deliveryIntervalMs) {
throw new Error('Missing required deliveryIntervalMs in EventDispatcherConfig');
}
if (!config.retryIntervalMs) {
throw new Error('Missing required retryIntervalMs in EventDispatcherConfig');
}
if (!config.maxRetryDelayMs) {
throw new Error('Missing required maxRetryDelayMs in EventDispatcherConfig');
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but this could probably be made into a loop to simplify.

@felipecsl
Copy link
Member Author

thanks for the review 🙏🏽

@felipecsl felipecsl merged commit 0fae041 into main Nov 26, 2024
8 checks passed
@felipecsl felipecsl deleted the felipecsl--event-dispatcher-api branch November 26, 2024 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants