Skip to content

refactor(sdk-client): prefer interfaces over classes in datasource#1067

Merged
joker23 merged 4 commits intomainfrom
szhang/SDK-1706-1769017426-prefer-interfaces-over-classes
Jan 26, 2026
Merged

refactor(sdk-client): prefer interfaces over classes in datasource#1067
joker23 merged 4 commits intomainfrom
szhang/SDK-1706-1769017426-prefer-interfaces-over-classes

Conversation

@joker23
Copy link
Copy Markdown
Contributor

@joker23 joker23 commented Jan 21, 2026

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

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:

  • Convert DataSourceState enum to a union type with a const object for backward compatibility
  • Convert DataSourceEventHandler class to interface + factory function (createDataSourceEventHandler)
  • Convert DataSourceStatusManager class to interface + factory function (createDataSourceStatusManager)
  • Convert Requestor class to interface + factory function (createRequestor)
  • Update imports to use named imports instead of default imports

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

  • Verify DataSourceState const object values match the original enum values
  • Confirm the eslint-disable for @typescript-eslint/no-redeclare is acceptable (needed because type and const share the same name for backward compatibility)
  • Check that factory functions maintain identical behavior to original class constructors

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.

  • Replaces DataSourceState enum with a string union type and adds DataSourceState const for compatibility
  • Converts DataSourceEventHandler, DataSourceStatusManager, and Requestor from classes to interfaces plus create*/makeRequestor factories using closure-based state
  • Updates usages: state updates now pass string literals (e.g., "INITIALIZING", "CLOSED", "VALID"); imports switched to named imports
  • Adjusts DataManager, BrowserDataManager, PollingProcessor, and StreamingProcessor to the new interfaces; no intended behavioral changes
  • Updates tests to use new factories and named imports

Written by Cursor Bugbot for commit 91cc9f9. This will update automatically on new commits. Configure here.

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>
@joker23 joker23 requested a review from a team as a code owner January 21, 2026 17:57
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 25394 bytes
Compressed size limit: 26000
Uncompressed size: 124693 bytes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 21, 2026

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 171249 bytes
Compressed size limit: 200000
Uncompressed size: 797978 bytes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 21, 2026

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 23264 bytes
Compressed size limit: 25000
Uncompressed size: 80869 bytes

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 21, 2026

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 18984 bytes
Compressed size limit: 20000
Uncompressed size: 98086 bytes

@joker23 joker23 added the devin-pr PRs created by Devin AI label Jan 21, 2026
@joker23 joker23 marked this pull request as draft January 21, 2026 23:10
@joker23 joker23 force-pushed the szhang/SDK-1706-1769017426-prefer-interfaces-over-classes branch from 933d0c1 to 9433978 Compare January 22, 2026 16:40
@joker23 joker23 force-pushed the szhang/SDK-1706-1769017426-prefer-interfaces-over-classes branch from 9433978 to 1e0ea26 Compare January 22, 2026 16:55
@joker23 joker23 marked this pull request as ready for review January 22, 2026 16:57
@devin-ai-integration
Copy link
Copy Markdown
Contributor

Package Size Diff Report

@launchdarkly/js-client-sdk-common (size limit: 20,000 bytes brotli)

Metric Main PR Diff
Raw 99,589 bytes 98,360 bytes -1,229 bytes (-1.23%)
Brotli 19,322 bytes 18,992 bytes -330 bytes (-1.70%)

@launchdarkly/js-client-sdk (size limit: 25,000 bytes brotli)

Metric Main PR Diff
Raw 81,328 bytes 81,036 bytes -292 bytes (-0.35%)
Brotli 23,330 bytes 23,301 bytes -29 bytes (-0.12%)

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.

@joker23
Copy link
Copy Markdown
Contributor Author

joker23 commented Jan 22, 2026

Can confirm ^ is correct

@joker23 joker23 merged commit 8f59982 into main Jan 26, 2026
37 checks passed
@joker23 joker23 deleted the szhang/SDK-1706-1769017426-prefer-interfaces-over-classes branch January 26, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr PRs created by Devin AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants