Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
b9011e6
Refactor InLocalStorage to use the storage from options
EmilianoSanchez May 22, 2025
61911ec
Make validateCache async to support async storages
EmilianoSanchez May 23, 2025
db1f424
Merge branch 'inlocalstorage_async_validateCache' into inlocalstorage…
EmilianoSanchez May 27, 2025
358a6b7
Place 'setChangeNumber' call as last operation inside storage 'update…
EmilianoSanchez May 27, 2025
4411c5d
Implement basic storageAdapter to support async storages with getItem…
EmilianoSanchez May 27, 2025
9f84077
Merge branch 'main' into inlocalstorage_async_validateCache
EmilianoSanchez May 30, 2025
9f8ca5a
Merge branch 'inlocalstorage_async_validateCache' into inlocalstorage…
EmilianoSanchez May 30, 2025
6d0f274
Merge branch 'inlocalstorage_wrapper' into inlocalstorage_storageAdapter
EmilianoSanchez May 30, 2025
b550042
Tests
EmilianoSanchez May 30, 2025
f1de8a8
Merge pull request #416 from splitio/development
EmilianoSanchez Jun 3, 2025
4b0988d
Update types
EmilianoSanchez Jun 23, 2025
299585b
refactor: rename Storage interface to StorageWrapper for clarity and …
EmilianoSanchez Jul 18, 2025
a598646
Merge branch 'development' into inlocalstorage_async_validateCache
EmilianoSanchez Jul 30, 2025
6b5eaca
Polishing
EmilianoSanchez Jul 30, 2025
468f119
Merge branch 'inlocalstorage_async_validateCache' into inlocalstorage…
EmilianoSanchez Jul 30, 2025
2bcf4d4
Merge branch 'inlocalstorage_wrapper' into inlocalstorage_storageAdapter
EmilianoSanchez Jul 30, 2025
c567f2e
Polishing
EmilianoSanchez Jul 30, 2025
96eaea0
Break the PR into smaller PRs
EmilianoSanchez Jul 30, 2025
70ea6d4
Revert "Break the PR into smaller PRs"
EmilianoSanchez Jul 30, 2025
3d3578b
Polishing
EmilianoSanchez Jul 30, 2025
02f0235
Merge branch 'inlocalstorage_async_validateCache' into inlocalstorage…
EmilianoSanchez Jul 30, 2025
71258da
Merge branch 'inlocalstorage_wrapper' into inlocalstorage_reorder_ope…
EmilianoSanchez Jul 30, 2025
47a8cc2
Merge branch 'inlocalstorage_reorder_operations' into inlocalstorage_…
EmilianoSanchez Jul 30, 2025
e0ef9cd
feat: add WebStorage type check and optimize storage adapter usage
EmilianoSanchez Jul 30, 2025
60aa25d
refactor: move storageAdapter to dedicated file and update imports
EmilianoSanchez Jul 31, 2025
7ac0aac
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Jul 31, 2025
1cae832
unit tests
EmilianoSanchez Jul 31, 2025
f1f5bf5
rc
EmilianoSanchez Jul 31, 2025
cb22017
Add unit test
EmilianoSanchez Aug 1, 2025
6bb2930
optimize StorageAdapter's length and key methods by using arrays inst…
EmilianoSanchez Aug 1, 2025
a7d3246
refactor: rename save method to whenSaved
EmilianoSanchez Aug 2, 2025
c594a6a
optimize StorageAdapter using an internal keys array and cache object
EmilianoSanchez Aug 4, 2025
a1c091b
refactor: split StorageWrapper into sync and async interfaces for bet…
EmilianoSanchez Aug 4, 2025
98d0ef7
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Aug 4, 2025
1c09903
Revert commit 70ea6d424d08928e81b496ce6ffed3e262b19cf6.
EmilianoSanchez Aug 11, 2025
afdf656
Add and use StorageAdapter::save method
EmilianoSanchez Aug 11, 2025
2e26d79
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Aug 11, 2025
1cc876b
refactor: call storage::save in updaters and remove from cache classes
EmilianoSanchez Aug 12, 2025
d5cdf7f
Merge pull request #419 from splitio/inlocalstorage_async_validateCache
EmilianoSanchez Aug 12, 2025
07dedd7
Polishing
EmilianoSanchez Aug 12, 2025
dc1ea50
Merge pull request #420 from splitio/inlocalstorage_wrapper
EmilianoSanchez Aug 12, 2025
a52eab3
Merge branch 'inlocalstorage_baseline' into inlocalstorage_storageAda…
EmilianoSanchez Aug 12, 2025
24bc14a
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Aug 12, 2025
a7edc8d
rc
EmilianoSanchez Aug 12, 2025
2934838
Merge pull request #428 from splitio/development
EmilianoSanchez Sep 10, 2025
ad6857a
Merge branch 'main' into inlocalstorage_baseline
EmilianoSanchez Sep 15, 2025
fb3b97a
Merge branch 'inlocalstorage_baseline' into inlocalstorage_storageAda…
EmilianoSanchez Sep 15, 2025
09f15de
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Sep 15, 2025
4e4df83
Avoid using wrapper for validation
EmilianoSanchez Sep 16, 2025
d04eb63
Simplify StorageWrapper interface
EmilianoSanchez Sep 16, 2025
0c22f4d
Merge branch 'inlocalstorage_storageAdapter' into inlocalstorage_sess…
EmilianoSanchez Sep 16, 2025
f45dcc7
Merge pull request #424 from splitio/inlocalstorage_storageAdapter
EmilianoSanchez Sep 16, 2025
daa5c31
Merge pull request #423 from splitio/inlocalstorage_sessionStorage
EmilianoSanchez Sep 16, 2025
c705834
rc
EmilianoSanchez Sep 16, 2025
987e8c5
Update links to public docs
EmilianoSanchez Sep 18, 2025
1cb9085
stable version
EmilianoSanchez Sep 18, 2025
240fec6
Log sdk version
EmilianoSanchez Sep 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.6.0 (September 18, 2025)
- Added `storage.wrapper` configuration option to allow the SDK to use a custom storage wrapper for the storage type `LOCALSTORAGE`. Default value is `window.localStorage`.

2.5.0 (September 10, 2025)
- Added `factory.getRolloutPlan()` method for standalone server-side SDKs, which returns the rollout plan snapshot from the storage.
- Added `initialRolloutPlan` configuration option for standalone client-side SDKs, which allows preloading the SDK storage with a snapshot of the rollout plan.
Expand Down Expand Up @@ -51,6 +54,15 @@
- Removed internal ponyfills for `Map` and `Set` global objects, dropping support for IE and other outdated browsers. The SDK now requires the runtime environment to support these features natively or to provide a polyfill.
- Removed the `sync.localhostMode` configuration option to plug the LocalhostMode module.

1.17.1 (July 25, 2025)
- Updated the Redis storage to avoid lazy require of the `ioredis` dependency when the SDK is initialized.
- Updated some transitive dependencies for vulnerability fixes.
- Bugfix - Enhanced HTTP client module to implement timeouts for failing requests that might otherwise remain pending indefinitely on some Fetch API implementations, pausing the SDK synchronization process.
- Bugfix - Properly handle rejected promises when using targeting rules with segment matchers in consumer modes (e.g., Redis and Pluggable storages).
- Bugfix - Sanitize the `SplitSDKMachineName` header value to avoid exceptions on HTTP/S requests when it contains non ISO-8859-1 characters (Related to issue https://github.com/splitio/javascript-client/issues/847).
- Bugfix - Fixed an issue with the SDK_UPDATE event on server-side, where it was not being emitted if there was an empty segment and the SDK received a feature flag update notification.
- Bugfix - Fixed an issue with the server-side polling manager that caused dangling timers when the SDK was destroyed before it was ready.

1.17.0 (September 6, 2024)
- Added `sync.requestOptions.getHeaderOverrides` configuration option to enhance SDK HTTP request Headers for Authorization Frameworks.
- Added `isTimedout` and `lastUpdate` properties to IStatusInterface to keep track of the timestamp of the last SDK event, used on React and Redux SDKs.
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ To learn more about Split, contact hello@split.io, or get started with feature f

Split has built and maintains SDKs for:

* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
* Android [Github](https://github.com/splitio/android-client) [Docs](https://help.split.io/hc/en-us/articles/360020343291-Android-SDK)
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/6495326064397-Angular-utilities)
* Elixir thin-client [Github](https://github.com/splitio/elixir-thin-client) [Docs](https://help.split.io/hc/en-us/articles/26988707417869-Elixir-Thin-Client-SDK)
* Flutter [Github](https://github.com/splitio/flutter-sdk-plugin) [Docs](https://help.split.io/hc/en-us/articles/8096158017165-Flutter-plugin)
* GO [Github](https://github.com/splitio/go-client) [Docs](https://help.split.io/hc/en-us/articles/360020093652-Go-SDK)
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://help.split.io/hc/en-us/articles/360020401491-iOS-SDK)
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
* JavaScript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://help.split.io/hc/en-us/articles/360058730852-Browser-SDK)
* Node.js [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
* PHP thin-client [Github](https://github.com/splitio/php-thin-client) [Docs](https://help.split.io/hc/en-us/articles/18305128673933-PHP-Thin-Client-SDK)
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
* React [Github](https://github.com/splitio/react-client) [Docs](https://help.split.io/hc/en-us/articles/360038825091-React-SDK)
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://help.split.io/hc/en-us/articles/4406066357901-React-Native-SDK)
* Redux [Github](https://github.com/splitio/redux-client) [Docs](https://help.split.io/hc/en-us/articles/360038851551-Redux-SDK)
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/net-sdk/)
* Android [Github](https://github.com/splitio/android-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/android-sdk/)
* Angular [Github](https://github.com/splitio/angular-sdk-plugin) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/angular-utilities/)
* Elixir thin-client [Github](https://github.com/splitio/elixir-thin-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/elixir-thin-client-sdk/)
* Flutter [Github](https://github.com/splitio/flutter-sdk-plugin) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/flutter-plugin/)
* GO [Github](https://github.com/splitio/go-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/go-sdk/)
* iOS [Github](https://github.com/splitio/ios-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/ios-sdk/)
* Java [Github](https://github.com/splitio/java-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/java-sdk/)
* JavaScript [Github](https://github.com/splitio/javascript-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/)
* JavaScript for Browser [Github](https://github.com/splitio/javascript-browser-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/browser-sdk/)
* Node.js [Github](https://github.com/splitio/javascript-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/nodejs-sdk/)
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/php-sdk/)
* PHP thin-client [Github](https://github.com/splitio/php-thin-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/php-thin-client-sdk/)
* Python [Github](https://github.com/splitio/python-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/python-sdk/)
* React [Github](https://github.com/splitio/react-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/react-sdk/)
* React Native [Github](https://github.com/splitio/react-native-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/react-native-sdk/)
* Redux [Github](https://github.com/splitio/redux-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/redux-sdk/)
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/server-side-sdks/ruby-sdk/)

For a comprehensive list of open source projects visit our [Github page](https://github.com/splitio?utf8=%E2%9C%93&query=%20only%3Apublic%20).

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "2.5.0",
"version": "2.6.0",
"description": "Split JavaScript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/logger/messages/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const codesInfo: [number, string][] = codesWarn.concat([
[c.IMPRESSION, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Feature flag: %s. Key: %s. Evaluation: %s. Label: %s'],
[c.IMPRESSION_QUEUEING, c.LOG_PREFIX_IMPRESSIONS_TRACKER +'Queueing corresponding impression.'],
[c.NEW_SHARED_CLIENT, 'New shared client instance created.'],
[c.NEW_FACTORY, 'New Split SDK instance created.'],
[c.NEW_FACTORY, 'New Split SDK instance created. %s'],
[c.EVENTS_TRACKER_SUCCESS, c.LOG_PREFIX_EVENTS_TRACKER + 'Successfully queued %s'],
[c.IMPRESSIONS_TRACKER_SUCCESS, c.LOG_PREFIX_IMPRESSIONS_TRACKER + 'Successfully stored %s impression(s).'],
[c.USER_CONSENT_UPDATED, 'UserConsent: consent status changed from %s to %s.'],
Expand Down
2 changes: 1 addition & 1 deletion src/sdkFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function sdkFactory(params: ISdkFactoryParams): SplitIO.ISDK | SplitIO.IA
initCallbacks.length = 0;
}

log.info(NEW_FACTORY);
log.info(NEW_FACTORY, [settings.version]);

// @ts-ignore
return objectAssign({
Expand Down
3 changes: 2 additions & 1 deletion src/storages/__tests__/RBSegmentsCacheSync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { IRBSegmentsCacheSync } from '../types';
import { fullSettings } from '../../utils/settingsValidation/__tests__/settings.mocks';

const cacheInMemory = new RBSegmentsCacheInMemory();
const cacheInLocal = new RBSegmentsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
// eslint-disable-next-line no-undef
const cacheInLocal = new RBSegmentsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'), localStorage);

describe.each([cacheInMemory, cacheInLocal])('Rule-based segments cache sync (Memory & LocalStorage)', (cache: IRBSegmentsCacheSync) => {

Expand Down
35 changes: 18 additions & 17 deletions src/storages/inLocalStorage/MySegmentsCacheInLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@ import { isNaNNumber } from '../../utils/lang';
import { AbstractMySegmentsCacheSync } from '../AbstractMySegmentsCacheSync';
import type { MySegmentsKeyBuilder } from '../KeyBuilderCS';
import { LOG_PREFIX, DEFINED } from './constants';
import { StorageAdapter } from '../types';

export class MySegmentsCacheInLocal extends AbstractMySegmentsCacheSync {

private readonly keys: MySegmentsKeyBuilder;
private readonly log: ILogger;
private readonly storage: StorageAdapter;

constructor(log: ILogger, keys: MySegmentsKeyBuilder) {
constructor(log: ILogger, keys: MySegmentsKeyBuilder, storage: StorageAdapter) {
super();
this.log = log;
this.keys = keys;
this.storage = storage;
// There is not need to flush segments cache like splits cache, since resetSegments receives the up-to-date list of active segments
}

protected addSegment(name: string): boolean {
const segmentKey = this.keys.buildSegmentNameKey(name);

try {
if (localStorage.getItem(segmentKey) === DEFINED) return false;
localStorage.setItem(segmentKey, DEFINED);
if (this.storage.getItem(segmentKey) === DEFINED) return false;
this.storage.setItem(segmentKey, DEFINED);
return true;
} catch (e) {
this.log.error(LOG_PREFIX + e);
Expand All @@ -33,8 +36,8 @@ export class MySegmentsCacheInLocal extends AbstractMySegmentsCacheSync {
const segmentKey = this.keys.buildSegmentNameKey(name);

try {
if (localStorage.getItem(segmentKey) !== DEFINED) return false;
localStorage.removeItem(segmentKey);
if (this.storage.getItem(segmentKey) !== DEFINED) return false;
this.storage.removeItem(segmentKey);
return true;
} catch (e) {
this.log.error(LOG_PREFIX + e);
Expand All @@ -43,18 +46,16 @@ export class MySegmentsCacheInLocal extends AbstractMySegmentsCacheSync {
}

isInSegment(name: string): boolean {
return localStorage.getItem(this.keys.buildSegmentNameKey(name)) === DEFINED;
return this.storage.getItem(this.keys.buildSegmentNameKey(name)) === DEFINED;
}

getRegisteredSegments(): string[] {
// Scan current values from localStorage
return Object.keys(localStorage).reduce((accum, key) => {
let segmentName = this.keys.extractSegmentName(key);

if (segmentName) accum.push(segmentName);

return accum;
}, [] as string[]);
const registeredSegments: string[] = [];
for (let i = 0, len = this.storage.length; i < len; i++) {
const segmentName = this.keys.extractSegmentName(this.storage.key(i)!);
if (segmentName) registeredSegments.push(segmentName);
}
return registeredSegments;
}

getKeysCount() {
Expand All @@ -63,16 +64,16 @@ export class MySegmentsCacheInLocal extends AbstractMySegmentsCacheSync {

protected setChangeNumber(changeNumber?: number) {
try {
if (changeNumber) localStorage.setItem(this.keys.buildTillKey(), changeNumber + '');
else localStorage.removeItem(this.keys.buildTillKey());
if (changeNumber) this.storage.setItem(this.keys.buildTillKey(), changeNumber + '');
else this.storage.removeItem(this.keys.buildTillKey());
} catch (e) {
this.log.error(e);
}
}

getChangeNumber() {
const n = -1;
let value: string | number | null = localStorage.getItem(this.keys.buildTillKey());
let value: string | number | null = this.storage.getItem(this.keys.buildTillKey());

if (value !== null) {
value = parseInt(value, 10);
Expand Down
37 changes: 19 additions & 18 deletions src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ import { isFiniteNumber, isNaNNumber, toNumber } from '../../utils/lang';
import { setToArray } from '../../utils/lang/sets';
import { usesSegments } from '../AbstractSplitsCacheSync';
import { KeyBuilderCS } from '../KeyBuilderCS';
import { IRBSegmentsCacheSync } from '../types';
import { IRBSegmentsCacheSync, StorageAdapter } from '../types';
import { LOG_PREFIX } from './constants';

export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {

private readonly keys: KeyBuilderCS;
private readonly log: ILogger;
private readonly storage: StorageAdapter;

constructor(settings: ISettings, keys: KeyBuilderCS) {
constructor(settings: ISettings, keys: KeyBuilderCS, storage: StorageAdapter) {
this.keys = keys;
this.log = settings.log;
this.storage = storage;
}

clear() {
this.getNames().forEach(name => this.remove(name));
localStorage.removeItem(this.keys.buildRBSegmentsTillKey());
this.storage.removeItem(this.keys.buildRBSegmentsTillKey());
}

update(toAdd: IRBSegment[], toRemove: IRBSegment[], changeNumber: number): boolean {
Expand All @@ -31,29 +33,28 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {

private setChangeNumber(changeNumber: number) {
try {
localStorage.setItem(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
localStorage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
this.storage.setItem(this.keys.buildRBSegmentsTillKey(), changeNumber + '');
this.storage.setItem(this.keys.buildLastUpdatedKey(), Date.now() + '');
} catch (e) {
this.log.error(LOG_PREFIX + e);
}
}

private updateSegmentCount(diff: number) {
const segmentsCountKey = this.keys.buildSplitsWithSegmentCountKey();
const count = toNumber(localStorage.getItem(segmentsCountKey)) + diff;
// @ts-expect-error
if (count > 0) localStorage.setItem(segmentsCountKey, count);
else localStorage.removeItem(segmentsCountKey);
const count = toNumber(this.storage.getItem(segmentsCountKey)) + diff;
if (count > 0) this.storage.setItem(segmentsCountKey, count + '');
else this.storage.removeItem(segmentsCountKey);
}

private add(rbSegment: IRBSegment): boolean {
try {
const name = rbSegment.name;
const rbSegmentKey = this.keys.buildRBSegmentKey(name);
const rbSegmentFromLocalStorage = localStorage.getItem(rbSegmentKey);
const previous = rbSegmentFromLocalStorage ? JSON.parse(rbSegmentFromLocalStorage) : null;
const rbSegmentFromStorage = this.storage.getItem(rbSegmentKey);
const previous = rbSegmentFromStorage ? JSON.parse(rbSegmentFromStorage) : null;

localStorage.setItem(rbSegmentKey, JSON.stringify(rbSegment));
this.storage.setItem(rbSegmentKey, JSON.stringify(rbSegment));

let usesSegmentsDiff = 0;
if (previous && usesSegments(previous)) usesSegmentsDiff--;
Expand All @@ -72,7 +73,7 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {
const rbSegment = this.get(name);
if (!rbSegment) return false;

localStorage.removeItem(this.keys.buildRBSegmentKey(name));
this.storage.removeItem(this.keys.buildRBSegmentKey(name));

if (usesSegments(rbSegment)) this.updateSegmentCount(-1);

Expand All @@ -84,13 +85,13 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {
}

private getNames(): string[] {
const len = localStorage.length;
const len = this.storage.length;
const accum = [];

let cur = 0;

while (cur < len) {
const key = localStorage.key(cur);
const key = this.storage.key(cur);

if (key != null && this.keys.isRBSegmentKey(key)) accum.push(this.keys.extractKey(key));

Expand All @@ -101,7 +102,7 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {
}

get(name: string): IRBSegment | null {
const item = localStorage.getItem(this.keys.buildRBSegmentKey(name));
const item = this.storage.getItem(this.keys.buildRBSegmentKey(name));
return item && JSON.parse(item);
}

Expand All @@ -117,7 +118,7 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {

getChangeNumber(): number {
const n = -1;
let value: string | number | null = localStorage.getItem(this.keys.buildRBSegmentsTillKey());
let value: string | number | null = this.storage.getItem(this.keys.buildRBSegmentsTillKey());

if (value !== null) {
value = parseInt(value, 10);
Expand All @@ -129,7 +130,7 @@ export class RBSegmentsCacheInLocal implements IRBSegmentsCacheSync {
}

usesSegments(): boolean {
const storedCount = localStorage.getItem(this.keys.buildSplitsWithSegmentCountKey());
const storedCount = this.storage.getItem(this.keys.buildSplitsWithSegmentCountKey());
const splitsWithSegmentsCount = storedCount === null ? 0 : toNumber(storedCount);

return isFiniteNumber(splitsWithSegmentsCount) ?
Expand Down
Loading