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
| import Storage from './storage'; | |
| enum Locals { | |
| ACCESS_TOKEN = 'access_token', | |
| REFRESH_TOKEN = 'refresh_token' | |
| } | |
| class Tokens extends Storage<Locals> { | |
| constructor() { | |
| super(); |
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
| interface IStorage { | |
| getItem(key: string): string | null; | |
| setItem(key: string, value: string): void; | |
| removeItem(key: string): void; | |
| } | |
| export default abstract class Storage<T extends string> { | |
| private readonly storage: IStorage; | |
| public constructor(getStorage = (): IStorage => window.localStorage) { |
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
| protected clearItem(key: T): void { | |
| this.storage.removeItem(key); | |
| } | |
| protected clearItems(keys: T[]): void { | |
| keys.forEach((key) => this.clearItem(key)); | |
| } |
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
| protected set(key: T, value: string): void { | |
| this.storage.setItem(key, value); | |
| } |
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
| protected get(key: T): string | null { | |
| return this.storage.getItem(key); | |
| } |
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
| abstract class Storage<T extends string> { | |
| private readonly storage: IStorage; | |
| public constructor(getStorage = (): IStorage => window.localStorage) { | |
| this.storage = getStorage(); | |
| } | |
| } |
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
| abstract class Storage<T extends string> { | |
| private readonly storage: IStorage; | |
| } |
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
| interface IStorage { | |
| getItem(key: string): string | null; | |
| setItem(key: string, value: string): void; | |
| removeItem(key: string): void; | |
| } |
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
| abstract class Storage<T extends string> {} |
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 MainApi extends HttpClient { | |
| private static classInstance?: MainApi; | |
| private constructor() { | |
| super('https://api.awesome-site.com'); | |
| } | |
| public static getInstance() { | |
| if (!this.classInstance) { | |
| this.classInstance = new MainApi(); |