Created
March 28, 2018 18:02
-
-
Save vandorjw/53c6a360eb91a45825e4cd92ce5bec83 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Storage { | |
/* | |
* This class exists to handle caching data between a page refresh. | |
* | |
* Usage example for setData: | |
* | |
* >> let myData = {"brand": "Example Brand", "brand_slug": "example_brand"} | |
* | |
* >> let store = new Storage('1', 'brands') | |
* >> store.setData(myData) | |
* | |
* Usage example for getData: | |
* | |
* >> let store = new Storage('1', 'brands') | |
* >> myData = store.getData() | |
* | |
*/ | |
constructor(resultId, dataType) | |
this.resultId = resultId | |
this.dataType = dataType | |
this.storageKey = dataType + "_" + resultId | |
} | |
getData() { | |
if (sessionStorage.getItem(this.storageKey) === null) { | |
return null | |
} else { | |
data = JSON.parse(sessionStorage.getItem(this.storageKey)) | |
} | |
} | |
setData(jsonObj) { | |
sessionStorage.setItem(this.storageKey, JSON.stringify(jsonObj)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment