Skip to content

Commit 3046752

Browse files
refactor: use segment type constants instead of string literals
1 parent 79a46be commit 3046752

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/evaluator/matchers/rbsegment.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IDependencyMatcherValue, ISplitEvaluator } from '../types';
55
import { thenable } from '../../utils/promise/thenable';
66
import { getMatching, keyParser } from '../../utils/key';
77
import { parser } from '../parser';
8+
import { STANDARD_SEGMENT, RULE_BASED_SEGMENT, LARGE_SEGMENT } from '../../utils/constants';
89

910

1011
export function ruleBasedSegmentMatcherContext(segmentName: string, storage: IStorageSync | IStorageAsync, log: ILogger) {
@@ -36,11 +37,11 @@ export function ruleBasedSegmentMatcherContext(segmentName: string, storage: ISt
3637
if (excluded.keys && excluded.keys.indexOf(matchingKey) !== -1) return true;
3738

3839
const isInSegment = (excluded.segments || []).map(({ type, name }) => {
39-
return type === 'standard' ?
40+
return type === STANDARD_SEGMENT ?
4041
storage.segments.isInSegment(name, matchingKey) :
41-
type === 'rule-based' ?
42+
type === RULE_BASED_SEGMENT ?
4243
ruleBasedSegmentMatcherContext(name, storage, log)({ key, attributes }, splitEvaluator) :
43-
type === 'large' && (storage as IStorageSync).largeSegments ?
44+
type === LARGE_SEGMENT && (storage as IStorageSync).largeSegments ?
4445
(storage as IStorageSync).largeSegments!.isInSegment(name, matchingKey) :
4546
false;
4647
});

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { SDK_SPLITS_ARRIVED } from '../../../readiness/constants';
77
import { ILogger } from '../../../logger/types';
88
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_UPDATE, SYNC_RBS_UPDATE, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
99
import { startsWith } from '../../../utils/lang';
10-
import { IN_RULE_BASED_SEGMENT, IN_SEGMENT } from '../../../utils/constants';
10+
import { IN_RULE_BASED_SEGMENT, IN_SEGMENT, RULE_BASED_SEGMENT, STANDARD_SEGMENT } from '../../../utils/constants';
1111
import { setToArray } from '../../../utils/lang/sets';
1212
import { SPLIT_UPDATE } from '../../streaming/constants';
1313

@@ -35,7 +35,7 @@ export function parseSegments(ruleEntity: ISplit | IRBSegment, matcherType: type
3535
const segments = new Set<string>();
3636
if (excluded && excluded.segments) {
3737
excluded.segments.forEach(({ type, name }) => {
38-
if ((type === 'standard' && matcherType === IN_SEGMENT) || (type === 'rule-based' && matcherType === IN_RULE_BASED_SEGMENT)) {
38+
if ((type === STANDARD_SEGMENT && matcherType === IN_SEGMENT) || (type === RULE_BASED_SEGMENT && matcherType === IN_RULE_BASED_SEGMENT)) {
3939
segments.add(name);
4040
}
4141
});

src/utils/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ export const FLAG_SPEC_VERSION = '1.3';
110110
export const IN_SEGMENT = 'IN_SEGMENT';
111111
export const IN_LARGE_SEGMENT = 'IN_LARGE_SEGMENT';
112112
export const IN_RULE_BASED_SEGMENT = 'IN_RULE_BASED_SEGMENT';
113+
114+
export const STANDARD_SEGMENT = 'standard';
115+
export const LARGE_SEGMENT = 'large';
116+
export const RULE_BASED_SEGMENT = 'rule-based';

0 commit comments

Comments
 (0)