This repository has been archived by the owner on Aug 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persist navigation state only for the current session (#110)
Fixes #78
- Loading branch information
1 parent
cfe6b96
commit f993983
Showing
2 changed files
with
11 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
'use strict'; | ||
|
||
const storages = { | ||
local: localStorage, | ||
session: sessionStorage, | ||
}; | ||
|
||
module.exports = { | ||
get(name, fallback) { | ||
const result = localStorage.getItem(name); | ||
get(name, fallback, storage = 'local') { | ||
const result = storages[storage].getItem(name); | ||
return result ? JSON.parse(result) : fallback; | ||
}, | ||
|
||
set(name, value) { | ||
localStorage.setItem(name, JSON.stringify(value)); | ||
set(name, value, storage = 'local') { | ||
storages[storage].setItem(name, JSON.stringify(value)); | ||
}, | ||
}; |