Conversation
Per CONTRIBUTING.md guidelines, refactor datasource code to prefer interfaces over classes for publicly exposed types: - Convert DataSourceState enum to union type with const object for backward compatibility - Convert DataSourceEventHandler class to interface + factory function - Convert DataSourceStatusManager class to interface + factory function - Convert Requestor class to interface + factory function - Update imports to use named imports instead of default imports Related issue: SDK-1706 Co-Authored-By: Steven Zhang <zhangksteven@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/browser size report |
|
@launchdarkly/js-client-sdk size report |
|
@launchdarkly/js-client-sdk-common size report |
933d0c1 to
9433978
Compare
9433978 to
1e0ea26
Compare
Package Size Diff Report@launchdarkly/js-client-sdk-common (size limit: 20,000 bytes brotli)
@launchdarkly/js-client-sdk (size limit: 25,000 bytes brotli)
The refactoring to interfaces + factory functions results in a small size reduction for both packages, with the sdk-client-common package seeing the most benefit (-1.70% brotli compressed). Both packages remain well under their size limits. |
|
Can confirm ^ is correct |
Requirements
Related issues
SDK-1706
Describe the solution you've provided
This PR refactors the datasource code to align with the CONTRIBUTING.md guidelines that prefer interfaces over classes for publicly exposed types.
Changes:
DataSourceStateenum to a union type with a const object for backward compatibilityDataSourceEventHandlerclass to interface + factory function (createDataSourceEventHandler)DataSourceStatusManagerclass to interface + factory function (createDataSourceStatusManager)Requestorclass to interface + factory function (createRequestor)The factory functions use closure-based state management to maintain private state without class fields. Default exports are preserved for backward compatibility.
Describe alternatives you've considered
Could have kept classes and only exposed interfaces, but the factory function pattern is cleaner and aligns better with the guidelines about bundle size optimization (functions minify better than class methods).
Additional context
All 272 unit tests pass, and browser SDK tests (96 tests) also pass. Lint checks pass.
Human review checklist
DataSourceStateconst object values match the original enum valueseslint-disablefor@typescript-eslint/no-redeclareis acceptable (needed because type and const share the same name for backward compatibility)Link to Devin run: https://app.devin.ai/sessions/88c5d6992adf45b7b386051a3d7ed13c
Requested by: Steven Zhang (@joker23)
Note
Refactors datasource components to prefer interfaces and factory functions, with backward-compat shims.
DataSourceStateenum with a string union type and addsDataSourceStateconst for compatibilityDataSourceEventHandler,DataSourceStatusManager, andRequestorfrom classes to interfaces pluscreate*/makeRequestorfactories using closure-based state"INITIALIZING","CLOSED","VALID"); imports switched to named importsDataManager,BrowserDataManager,PollingProcessor, andStreamingProcessorto the new interfaces; no intended behavioral changesWritten by Cursor Bugbot for commit 91cc9f9. This will update automatically on new commits. Configure here.