forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironmentKnownCache.ts
More file actions
37 lines (31 loc) · 981 Bytes
/
environmentKnownCache.ts
File metadata and controls
37 lines (31 loc) · 981 Bytes
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
34
35
36
37
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Environment } from './api/types';
/**
* Workaround temp cache until types are consolidated.
*/
export class EnvironmentKnownCache {
private _envs: Environment[] = [];
constructor(envs: Environment[]) {
this._envs = envs;
}
public get envs(): Environment[] {
return this._envs;
}
public addEnv(env: Environment): void {
const found = this._envs.find((e) => env.id === e.id);
if (!found) {
this._envs.push(env);
}
}
public updateEnv(oldValue: Environment, newValue: Environment | undefined): void {
const index = this._envs.findIndex((e) => oldValue.id === e.id);
if (index !== -1) {
if (newValue === undefined) {
this._envs.splice(index, 1);
} else {
this._envs[index] = newValue;
}
}
}
}