memento.ts ×12

Frontier kind: Code frontier

unlabeled · c_3d48c2820d3d

192 tests · 12828 LOC · 57 files · introduces 0 tests · 49 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges49 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1770 ranges12828 lines · 57 files · Browse complete extent
All tests (intent)
192 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 49 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/common/memento.ts 49 introduced LOC · 12 ranges

Open complete file

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 }
26 > memento.ts
27 > getMemento(scope: StorageScope, target: StorageTarget): Partial<T> {
28 switch (scope) {
29 case StorageScope.WORKSPACE: {
68 }
69 }
70 > memento.ts
71 > onDidChangeValue(scope: StorageScope, disposables: DisposableStore): Event<IStorageValueChangeEvent> {
72 return this.storageService.onDidChangeValue(scope, this.id, disposables);
73 }
74 > memento.ts
75 > saveMemento(): void {
76 Memento.workspaceMementos.get(this.id)?.save();
77 Memento.profileMementos.get(this.id)?.save();
79 Memento.applicationSharedMementos.get(this.id)?.save();
80 }
81 > memento.ts
82 > reloadMemento(scope: StorageScope): void {
83 let memento: ScopedMemento<unknown> | undefined;
84 switch (scope) {
99 memento?.reload();
100 }
101 > memento.ts
102 > static clear(scope: StorageScope): void {
103 switch (scope) {
104 case StorageScope.WORKSPACE:
116 }
117 }
118 > } memento.ts
119 >
120 > class ScopedMemento<T> {
121 >
122 > private mementoObj: Partial<T>;
123 >
124 > constructor(private id: string, private scope: StorageScope, private target: StorageTarget, private storageService: IStorageService) {
125 this.mementoObj = this.doLoad();
126 }
127 > memento.ts
128 > private doLoad(): Partial<T> {
129 try {
130 return this.storageService.getObject(this.id, this.scope, {});
139 return {};
140 }
141 > memento.ts
142 > getMemento(): Partial<T> {
143 return this.mementoObj;
144 }
145 > memento.ts
146 > reload(): void {
147
148 // Clear old
154 Object.assign(this.mementoObj, this.doLoad());
155 }
156 > memento.ts
157 > save(): void {
158 if (!isEmptyObject(this.mementoObj)) {
159 this.storageService.store(this.id, this.mementoObj, this.scope, this.target);