/** * Session storage object - singleton instance model */ export default class SessionStorage { // Static instance private static _instance: any; /** * * @private */ private _proxy: any; // Meta props private _metaProps = {}; // Create proxy constructor() { this._proxy = new Proxy({}, { get: (target: any, key: string): any => { if (key == "hasOwnProperty") { return (propertyName: any) => { if (propertyName == "__rv") { return !!(this._metaProps)["__rv"]; } } } else if (key == "__rv") { return (this._metaProps)["__rv"]; } return sessionStorage.getItem(key); }, set: (target: any, key: string, value: any): boolean => { if (key == "__rv") { (this._metaProps)["__rv"] = value; } else { sessionStorage.setItem(key, value); (this)[key] = value; } return true; }, defineProperty: (target: any, key: any, desc: any) => { if (key == "__rv") { if (!(this._metaProps)["__rv"]) (this._metaProps)["__rv"] = desc.value; } else { Object.defineProperty(this, key, desc); } return target; } }); } get proxy() { return this._proxy; } /** * Get a singleton version of this request */ public static get instance() { if (!this._instance) { this._instance = new SessionStorage(); } return this._instance.proxy; } }