Skip to content

Commit 5195943

Browse files
Reuse IN_SEGMENT string constant
1 parent 82ebe61 commit 5195943

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/storages/AbstractSplitsCacheSync.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ISplitsCacheSync } from './types';
22
import { ISplit } from '../dtos/types';
33
import { objectAssign } from '../utils/lang/objectAssign';
44
import { ISet } from '../utils/lang/sets';
5+
import { IN_SEGMENT } from '../utils/constants';
56

67
/**
78
* This class provides a skeletal implementation of the ISplitsCacheSync interface
@@ -93,7 +94,7 @@ export function usesSegments(split: ISplit) {
9394
const matchers = conditions[i].matcherGroup.matchers;
9495

9596
for (let j = 0; j < matchers.length; j++) {
96-
if (matchers[j].matcherType === 'IN_SEGMENT') return true;
97+
if (matchers[j].matcherType === IN_SEGMENT) return true;
9798
}
9899
}
99100

src/sync/polling/updaters/splitChangesUpdater.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED } from '../../../readiness/
88
import { ILogger } from '../../../logger/types';
99
import { SYNC_SPLITS_FETCH, SYNC_SPLITS_NEW, SYNC_SPLITS_REMOVED, SYNC_SPLITS_SEGMENTS, SYNC_SPLITS_FETCH_FAILS, SYNC_SPLITS_FETCH_RETRY } from '../../../logger/constants';
1010
import { startsWith } from '../../../utils/lang';
11+
import { IN_SEGMENT } from '../../../utils/constants';
1112

1213
type ISplitChangesUpdater = (noCache?: boolean, till?: number, splitUpdateNotification?: { payload: ISplit, changeNumber: number }) => Promise<boolean>
1314

@@ -33,7 +34,7 @@ export function parseSegments({ conditions }: ISplit): ISet<string> {
3334
const matchers = conditions[i].matcherGroup.matchers;
3435

3536
matchers.forEach(matcher => {
36-
if (matcher.matcherType === 'IN_SEGMENT') segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
37+
if (matcher.matcherType === IN_SEGMENT) segments.add(matcher.userDefinedSegmentMatcherData.segmentName);
3738
});
3839
}
3940

@@ -54,7 +55,7 @@ interface ISplitMutations {
5455
* @param filters splitFiltersValidation bySet | byName
5556
*/
5657
function matchFilters(featureFlag: ISplit, filters: ISplitFiltersValidation) {
57-
const { bySet: setsFilter, byName: namesFilter, byPrefix: prefixFilter} = filters.groupedFilters;
58+
const { bySet: setsFilter, byName: namesFilter, byPrefix: prefixFilter } = filters.groupedFilters;
5859
if (setsFilter.length > 0) return featureFlag.sets && featureFlag.sets.some((featureFlagSet: string) => setsFilter.indexOf(featureFlagSet) > -1);
5960

6061
const namesFilterConfigured = namesFilter.length > 0;
@@ -129,7 +130,7 @@ export function splitChangesUpdaterFactory(
129130

130131
/** Returns true if at least one split was updated */
131132
function isThereUpdate(flagsChange: [boolean | void, void | boolean[], void | boolean[], boolean | void] | [any, any, any]) {
132-
const [, added, removed, ] = flagsChange;
133+
const [, added, removed] = flagsChange;
133134
// There is at least one added or modified feature flag
134135
if (added && added.some((update: boolean) => update)) return true;
135136
// There is at least one removed feature flag

src/utils/constants/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,6 @@ export const ENABLED = 1;
106106
export const PAUSED = 2;
107107

108108
export const FLAG_SPEC_VERSION = '1.1';
109+
110+
// Matcher types
111+
export const IN_SEGMENT = 'IN_SEGMENT';

0 commit comments

Comments
 (0)