Skip to content

Conversation

@ZamoraEmmanuel
Copy link
Contributor

JavaScript commons library

What did you accomplish?

How do we test the changes introduced in this PR?

Extra Notes

@ZamoraEmmanuel ZamoraEmmanuel requested a review from a team as a code owner January 5, 2026 23:23
@ZamoraEmmanuel ZamoraEmmanuel marked this pull request as draft January 6, 2026 20:19

function updateSegment(segmentName: string, noCache?: boolean, till?: number, fetchOnlyNew?: boolean, retries?: number): Promise<boolean> {
log.debug(`${LOG_PREFIX_SYNC_SEGMENTS}Processing segment ${segmentName}`);
const sincePromise = Promise.resolve(segments.getChangeNumber(segmentName));
Copy link
Contributor

Choose a reason for hiding this comment

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

If metadata is only used inside the if condition, we should refactor it as:

if (readiness) {
  const metadata: SdkUpdateMetadata = {
    type: SdkUpdateMetadataKeys.SEGMENTS_UPDATE,
    names: []
  };
  readiness.segments.emit(SDK_SEGMENTS_ARRIVED, metadata);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Idem for splitChangesUpdater

/**
* Metadata keys for SDK update events.
*/
export enum SdkUpdateMetadataKeys {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion this enum should be removed and string constants should be used instead, because the SdkUpdateMetadata type in splitio.d.ts already defines the type field as a string literal union.

So, you can remove the enum and define the following constants in the readiness/constants.ts file:

...

// SdkUpdateMetadata types:
const FLAGS_UPDATE =  'FLAGS_UPDATE';
const SEGMENTS_UPDATE = 'SEGMENTS_UPDATE'

and reuse them across the code.

Using string literal unions rather than enum or const enum is a recommended practice for several reasons. For example, the output built code is smaller, const enum is incompatible with some build setups, etc.

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.

2 participants