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 (27 loc) · 1.28 KB
/
persistentState.ts
File metadata and controls
33 lines (27 loc) · 1.28 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 { inject, injectable, named } from 'inversify';
import 'reflect-metadata';
import { Memento } from 'vscode';
import { GLOBAL_MEMENTO, IMemento, IPersistentState, IPersistentStateFactory, WORKSPACE_MEMENTO } from './types';
class PersistentState<T> implements IPersistentState<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);
}
}
@injectable()
export class PersistentStateFactory implements IPersistentStateFactory {
constructor( @inject(IMemento) @named(GLOBAL_MEMENTO) private globalState: Memento,
@inject(IMemento) @named(WORKSPACE_MEMENTO) private workspaceState: Memento) { }
public createGlobalPersistentState<T>(key: string, defaultValue: T): IPersistentState<T> {
return new PersistentState<T>(this.globalState, key, defaultValue);
}
public createWorkspacePersistentState<T>(key: string, defaultValue: T): IPersistentState<T> {
return new PersistentState<T>(this.workspaceState, key, defaultValue);
}
}