Files
nocodb/packages/nc-gui/utils/memStorage.ts
braks d3a4bca8f3 feat(nc-gui): store sidebar states separately by id
# What's changed?

* use a sidebar id to identify the state
* use in memory storage to store the states
* use local storage to store persistent states
* add MemStorage class
2022-09-15 12:59:27 +02:00

37 lines
698 B
TypeScript

/**
* 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++}`
}
}