Skip to content

Commit 13777e3

Browse files
bump to commons 3.0.6; add LocalStorageBackedAsyncStore (FF-1980) (#62)
* bump to commons 3.0.6; add LocalStorageBackedAsyncStore (FF-1980) * remove comment
1 parent 6d612c9 commit 13777e3

9 files changed

+420
-376
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"webpack-cli": "^4.10.0"
5858
},
5959
"dependencies": {
60-
"@eppo/js-client-sdk-common": "3.0.2",
60+
"@eppo/js-client-sdk-common": "3.0.6",
6161
"md5": "^2.3.0"
6262
}
6363
}

src/configuration-factory.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {
2+
Flag,
3+
HybridConfigurationStore,
4+
IConfigurationStore,
5+
MemoryOnlyConfigurationStore,
6+
MemoryStore,
7+
} from '@eppo/js-client-sdk-common';
8+
9+
import { LocalStorageBackedAsyncStore } from './local-storage';
10+
11+
export function configurationStorageFactory(): IConfigurationStore<Flag> {
12+
if (hasWindowLocalStorage()) {
13+
// fallback to window.localStorage if available
14+
return new HybridConfigurationStore(
15+
new MemoryStore<Flag>(),
16+
new LocalStorageBackedAsyncStore<Flag>(window.localStorage),
17+
);
18+
}
19+
20+
return new MemoryOnlyConfigurationStore();
21+
}
22+
23+
export function hasWindowLocalStorage(): boolean {
24+
try {
25+
return typeof window !== 'undefined' && !!window.localStorage;
26+
} catch {
27+
// Chrome throws an error if local storage is disabled and you try to access it
28+
return false;
29+
}
30+
}

0 commit comments

Comments
 (0)