forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersistentState.ts
More file actions
33 lines (26 loc) · 1.18 KB
/
persistentState.ts
File metadata and controls
33 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Memento } from 'vscode';
export class PersistentState<T> {
constructor(private storage: Memento, private key: string, private defaultValue: T) { }
public get value(): T {
return this.storage.get<T>(this.key, this.defaultValue);
}
public set value(newValue: T) {
this.storage.update(this.key, newValue);
}
}
export interface IPersistentStateFactory {
createGlobalPersistentState<T>(key: string, defaultValue: T): PersistentState<T>;
createWorkspacePersistentState<T>(key: string, defaultValue: T): PersistentState<T>;
}
export class PersistentStateFactory implements IPersistentStateFactory {
constructor(private globalState: Memento, private workspaceState: Memento) { }
public createGlobalPersistentState<T>(key: string, defaultValue: T): PersistentState<T> {
return new PersistentState<T>(this.globalState, key, defaultValue);
}
public createWorkspacePersistentState<T>(key: string, defaultValue: T): PersistentState<T> {
return new PersistentState<T>(this.workspaceState, key, defaultValue);
}
}