Created
January 29, 2018 08:36
-
-
Save mrxf/fbabefffef27d098ae2a9d8742b470e1 to your computer and use it in GitHub Desktop.
store your date in global
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
/** | |
* tool for store data in global | |
*/ | |
class GlobalStorage{ | |
/** | |
* init Global Storage | |
* @param {string} globalKey key for store | |
*/ | |
constructor(globalKey = "app") { | |
this.globalKey = globalKey; | |
if(!global.hasOwnProperty(globalKey)) { | |
global[globalKey] = new Object(); | |
} | |
} | |
/** | |
* store a value in a given key | |
* @param {string} key key for storage | |
* @param {any} value value for storage | |
*/ | |
set(key, value) { | |
global[this.globalKey][key] = value; | |
} | |
/** | |
* get the value | |
* @param {string} key key for value | |
*/ | |
get(key) { | |
return global[this.globalKey][key]; | |
} | |
} | |
module.exports = GlobalStorage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment