/** * Local storage object - singleton instance model */ export default class LocalStorage { // Static instance private static _instance: any; /** * * @private */ private _proxy: any; // Meta props private _metaProps: any = {}; // 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 localStorage.getItem(key); }, set: (target: any, key: string, value: any): boolean => { if (key == "__rv") { this._metaProps["__rv"] = value; } else { localStorage.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 LocalStorage(); } return this._instance.proxy; } }