Skip to content

Conversation

@kinyoklion
Copy link
Member

@kinyoklion kinyoklion commented Sep 24, 2024

Most of this PR is refactoring to move data source handling our of the common code. This also moves functionality, such as setConnectionMode out of the common code.

Currently the MobileDataManager is in the RN SDK, but it should be moved to some kind of non-browser common when we implement SDKs like node or electron.

A large amount of the code in this PR is tests for data source handling and moving existing code.

This PR does not add automatic starting/stopping of the stream.

BEGIN_COMMIT_OVERRIDE
feat: Refactor data source connection handling.
feat: Add support for js-client-sdk style initialization.
END_COMMIT_OVERRIDE

* Note: The requestor is implemented independently from polling such that it can be used to
* make a one-off request.
*
* @internal
Copy link
Member Author

Choose a reason for hiding this comment

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

To allow usage outside the common package.

},
testPathIgnorePatterns: ['./dist'],
testPathIgnorePatterns: ['./dist', './src'],
testMatch: ["**.test.ts"]
Copy link
Member Author

Choose a reason for hiding this comment

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

The shared test code didn't contain tests, which made it angry.

"scripts": {
"clean": "rimraf dist",
"build": "rollup -c rollup.config.js",
"build": "tsc --noEmit && rollup -c rollup.config.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

Make sure TS errors actually fail the build.

// TODO: Handle wait for network results in a meaningful way. SDK-707

try {
const payload = await requestor.requestPayload();
Copy link
Member Author

Choose a reason for hiding this comment

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

The current SDK only does this once. We may want to consider if we want to at least do it twice.

const plainContextString = JSON.stringify(Context.toLDContext(context));
const requestor = this.getRequestor(plainContextString);

// TODO: Handle wait for network results in a meaningful way. SDK-707
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it just isn't an option for this SDK?

const uri = getPollingUri(this.config.serviceEndpoints, path, parameters);
return new Requestor(this.platform.requests, uri, headers, method, body);
}
// TODO: Automatically start streaming if event handlers are registered.
Copy link
Member Author

Choose a reason for hiding this comment

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

Made a ticket for this. Was originally in scope for this ticket, but it already ended up being too large.

@kinyoklion kinyoklion marked this pull request as ready for review September 24, 2024 18:07
@kinyoklion kinyoklion requested a review from a team as a code owner September 24, 2024 18:07
flagManager: FlagManager,
configuration: Configuration,
baseHeaders: LDHeaders,
emitter: LDEmitter,
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider emitter -> errorEmitter.

Copy link
Member Author

Choose a reason for hiding this comment

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

The emitter is not error only, but all emissions. Though this does only use it in that domain. It doesn't need to. I could make an emit error function if that makes more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically DataManager only emits errors in the implementations we have, but it could emit any supported event type. Though maybe we don't want that? If we didn't then we would need to pass something other than an emitter, as an emitter lets you emit any event type.

undefined,
diagnosticsManager,
start,
false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this start case covered by a call to setEventSendingEnabled?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. It makes it easier to control from the specific SDK implementations. RN conditionally starts it and the Browser SDK always starts it.

@kinyoklion kinyoklion merged commit 53f5bb8 into main Sep 25, 2024
22 checks passed
@kinyoklion kinyoklion deleted the rlamb/sdk-195/support-js-style-initialization branch September 25, 2024 22:20
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