Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 0 additions & 32 deletions lib/createLocalStorage.js

This file was deleted.

25 changes: 19 additions & 6 deletions lib/createSecureSessionStorage.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import createStore from './helpers/store';
import { load, save } from './helpers/secureSessionStorage';
import { attachOnUnload } from './helpers/dom';

/**
* Create the secure session storage instance and attach the unload handler
* to persist the state.
* @param {Array} keys
* @return {{set, getState, get, reset, remove}}
*/
export default (keys = []) => {
const store = createStore(load(keys));

attachOnUnload(() => {
save(keys, store.getState());
});
if ('onpagehide' in window) {
const handlePageShow = () => {
// This does not need to do anything. The main purpose is just to reset window.name and sessionStorage to fix the Safari 13.1 described below
load(keys);
};

const handlePageHide = () => {
// Cannot use !event.persisted because Safari 13.1 does not send that when you are navigating on the same domain
save(keys, store.getState());
};

window.addEventListener('pageshow', handlePageShow, true);
window.addEventListener('pagehide', handlePageHide, true);
} else {
const handleUnload = () => {
save(keys, store.getState());
};
window.addEventListener('unload', handleUnload, true);
}

return store;
};
12 changes: 0 additions & 12 deletions lib/helpers/dom.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
export const attachOnUnload = (cb) => {
if (window.addEventListener) {
return window.addEventListener('unload', cb, false);
}

if (window.attachEvent) {
return window.attachEvent('onunload', cb);
}

throw new Error('No method for adding event listeners!');
};

const loadScriptHelper = ({ path, integrity }, cb) => {
const script = document.createElement('script');

Expand Down