1
>
/*---------------------------------------------------------------------------------------------
memento.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { IStorageService, IStorageValueChangeEvent, StorageScope, StorageTarget } from '../../platform/storage/common/storage.js';
7
>
import { isEmptyObject } from '../../base/common/types.js';
8
>
import { onUnexpectedError } from '../../base/common/errors.js';
9
>
import { DisposableStore } from '../../base/common/lifecycle.js';
10
>
import { Event } from '../../base/common/event.js';
11
>
12
>
export class Memento<T extends object> {
13
>
14
>
private static readonly applicationMementos = new Map<string, ScopedMemento<unknown>>();
15
>
private static readonly applicationSharedMementos = new Map<string, ScopedMemento<unknown>>();
16
>
private static readonly profileMementos = new Map<string, ScopedMemento<unknown>>();
17
>
private static readonly workspaceMementos = new Map<string, ScopedMemento<unknown>>();
18
>
19
>
private static readonly COMMON_PREFIX = 'memento/';
20
>
21
>
private readonly id: string;
22
>
23
>
constructor(id: string, private storageService: IStorageService) {
24
this.id = Memento.COMMON_PREFIX + id;
25
}
27
>
getMemento(scope: StorageScope, target: StorageTarget): Partial<T> {
28
switch (scope) {
29
case StorageScope.WORKSPACE: {