Skip to content

Commit 6602ea2

Browse files
committed
Replace sessionStorage with localStorage
1 parent 16398e9 commit 6602ea2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/__tests__/storage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ describe('storage', () => {
1010
});
1111

1212
test('get with invalid existing storage value', () => {
13-
window.sessionStorage.setItem(STORE_KEY, '"abc"');
13+
window.localStorage.setItem(STORE_KEY, '"abc"');
1414

1515
expect(get('key1')).toBeUndefined();
1616

17-
window.sessionStorage.setItem(STORE_KEY, '');
17+
window.localStorage.setItem(STORE_KEY, '');
1818

1919
expect(get('key1')).toBeUndefined();
2020
});

src/storage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const STORE_KEY = 'mt-link-javascript-sdk';
22

3-
const sessionStorage = window.sessionStorage;
3+
const localStorage = window.localStorage;
44

55
function getStorageObject(): { [key: string]: string } {
6-
const stringifiedData = sessionStorage.getItem(STORE_KEY) || '';
6+
const stringifiedData = localStorage.getItem(STORE_KEY) || '';
77
let data = {};
88

99
try {
@@ -23,14 +23,14 @@ export function set(key: string, value: string): void {
2323
const data = getStorageObject();
2424
data[key] = value;
2525

26-
sessionStorage.setItem(STORE_KEY, JSON.stringify(data));
26+
localStorage.setItem(STORE_KEY, JSON.stringify(data));
2727
}
2828

2929
export function del(key: string): void {
3030
const data = getStorageObject();
3131
delete data[key];
3232

33-
sessionStorage.setItem(STORE_KEY, JSON.stringify(data));
33+
localStorage.setItem(STORE_KEY, JSON.stringify(data));
3434
}
3535

3636
export default {

0 commit comments

Comments
 (0)