Skip to content

Instantly share code, notes, and snippets.

@mrxf
Created January 29, 2018 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrxf/fbabefffef27d098ae2a9d8742b470e1 to your computer and use it in GitHub Desktop.
Save mrxf/fbabefffef27d098ae2a9d8742b470e1 to your computer and use it in GitHub Desktop.
store your date in global
/**
* 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