mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
698 B
36 lines
698 B
/** |
|
* Stores all currently created store instances |
|
*/ |
|
export class MemStorage<T = any> { |
|
public currentId = 0 |
|
public items = new Map<string, T>() |
|
static instance: MemStorage |
|
|
|
public static getInstance(): MemStorage { |
|
if (!MemStorage.instance) { |
|
MemStorage.instance = new MemStorage() |
|
} |
|
|
|
return MemStorage.instance |
|
} |
|
|
|
public set(id: string, item: T) { |
|
return this.items.set(id, item) |
|
} |
|
|
|
public get(id: string) { |
|
return this.items.get(id) |
|
} |
|
|
|
public has(id: string) { |
|
return this.items.has(id) |
|
} |
|
|
|
public remove(id: string) { |
|
return this.items.delete(id) |
|
} |
|
|
|
public getId(prefix?: string) { |
|
return `${prefix}${this.currentId++}` |
|
} |
|
}
|
|
|