Skip to content

Commit 69f63d1

Browse files
rc
1 parent ac8d76b commit 69f63d1

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splitsoftware/splitio-commons",
3-
"version": "2.1.1-rc.1",
3+
"version": "2.1.1-rc.2",
44
"description": "Split JavaScript SDK common components",
55
"main": "cjs/index.js",
66
"module": "esm/index.js",

src/evaluator/parser/__tests__/index.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { parser } from '..';
33
import { keyParser } from '../../../utils/key';
44
import { ISplitCondition } from '../../../dtos/types';
5-
import { bucket } from '../../../utils/murmur3/murmur3';
65
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';
76

87
test('PARSER / if user is in segment all 100%:on', async function () {
@@ -662,8 +661,6 @@ test('PARSER / if user is in segment all then split 20%:A,20%:B,60%:A', async fu
662661
let evaluation = await evaluator(keyParser('aa'), 31, 100, 31);
663662
expect(evaluation.treatment).toBe('A'); // 20%:A // bucket 6 with murmur3
664663

665-
console.log(bucket('b297', 31));
666-
667664
evaluation = await evaluator(keyParser('b297'), 31, 100, 31);
668665
expect(evaluation.treatment).toBe('B'); // 20%:B // bucket 34 with murmur3
669666

src/storages/inLocalStorage/SplitsCacheInLocal.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
3131
else localStorage.removeItem(key);
3232
}
3333

34-
private _decrementCounts(split: ISplit | null) {
34+
private _decrementCounts(split: ISplit) {
3535
try {
36-
if (split) {
37-
const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
38-
this._decrementCount(ttKey);
36+
const ttKey = this.keys.buildTrafficTypeKey(split.trafficTypeName);
37+
this._decrementCount(ttKey);
3938

40-
if (usesSegments(split)) {
41-
const segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
42-
this._decrementCount(segmentsCountKey);
43-
}
39+
if (usesSegments(split)) {
40+
const segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
41+
this._decrementCount(segmentsCountKey);
4442
}
4543
} catch (e) {
4644
this.log.error(LOG_PREFIX + e);
@@ -93,12 +91,14 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
9391
const splitFromLocalStorage = localStorage.getItem(splitKey);
9492
const previousSplit = splitFromLocalStorage ? JSON.parse(splitFromLocalStorage) : null;
9593

94+
if (previousSplit) {
95+
this._decrementCounts(previousSplit);
96+
this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
97+
}
98+
9699
localStorage.setItem(splitKey, JSON.stringify(split));
97100

98101
this._incrementCounts(split);
99-
this._decrementCounts(previousSplit);
100-
101-
if (previousSplit) this.removeFromFlagSets(previousSplit.name, previousSplit.sets);
102102
this.addToFlagSets(split);
103103

104104
return true;
@@ -116,7 +116,7 @@ export class SplitsCacheInLocal extends AbstractSplitsCacheSync {
116116
localStorage.removeItem(this.keys.buildSplitKey(name));
117117

118118
this._decrementCounts(split);
119-
if (split) this.removeFromFlagSets(split.name, split.sets);
119+
this.removeFromFlagSets(split.name, split.sets);
120120

121121
return true;
122122
} catch (e) {

0 commit comments

Comments
 (0)