Files
cloudbeaver/webapp/packages/core-settings/src/SettingsSource.ts
T
2021-06-30 14:35:23 +03:00

35 lines
826 B
TypeScript

/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2021 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { ISettingsSource } from './ISettingsSource';
export class SettingsSource implements ISettingsSource {
protected store = new Map<string, any>();
constructor(protected fallback?: ISettingsSource) {}
has(key: string): boolean {
return this.store.has(key) || !!this.fallback?.has(key);
}
getValue(key: string): any | undefined {
if (this.fallback?.has(key)) {
return this.fallback.getValue(key);
}
return this.store.get(key);
}
setValue(key: string, value: any): void {
this.store.set(key, value);
}
clear(): void {
this.store.clear();
}
}