Skip to content

Commit ad0bd9b

Browse files
author
Benjamin Pasero
committed
💄
1 parent efe237d commit ad0bd9b

4 files changed

Lines changed: 8 additions & 44 deletions

File tree

src/vs/platform/storage/common/storage.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,6 @@ export interface IStorageService {
2020
*/
2121
store(key: string, value: any, scope?: StorageScope): void;
2222

23-
/**
24-
* Swap the value of a stored element to one of the two provided
25-
* values and use the defaultValue if no element with the given key
26-
* exists.
27-
*
28-
* The optional scope argument allows to define the scope of the operation.
29-
*/
30-
swap(key: string, valueA: any, valueB: any, scope?: StorageScope, defaultValue?: any): void;
31-
3223
/**
3324
* Delete an element stored under the provided key from local storage.
3425
*
@@ -80,7 +71,6 @@ export enum StorageScope {
8071
export const NullStorageService: IStorageService = {
8172
_serviceBrand: undefined,
8273
store() { return undefined; },
83-
swap() { return undefined; },
8474
remove() { return undefined; },
8575
get(a, b, defaultValue) { return defaultValue; },
8676
getInteger(a, b, defaultValue) { return defaultValue; },

src/vs/platform/storage/common/storageService.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,6 @@ export class StorageService implements IStorageService {
149149
return value;
150150
}
151151

152-
public remove(key: string, scope = StorageScope.GLOBAL): void {
153-
const storage = (scope === StorageScope.GLOBAL) ? this._globalStorage : this._workspaceStorage;
154-
const storageKey = this.toStorageKey(key, scope);
155-
156-
// Remove
157-
storage.removeItem(storageKey);
158-
}
159-
160-
public swap(key: string, valueA: any, valueB: any, scope = StorageScope.GLOBAL, defaultValue?: any): void {
161-
const value = this.get(key, scope);
162-
if (types.isUndefinedOrNull(value) && defaultValue) {
163-
this.store(key, defaultValue, scope);
164-
} else if (value === valueA.toString()) { // Convert to string because store is string based
165-
this.store(key, valueB, scope);
166-
} else {
167-
this.store(key, valueA, scope);
168-
}
169-
}
170-
171152
public getInteger(key: string, scope = StorageScope.GLOBAL, defaultValue?: number): number {
172153
const value = this.get(key, scope, defaultValue);
173154

@@ -192,6 +173,14 @@ export class StorageService implements IStorageService {
192173
return value ? true : false;
193174
}
194175

176+
public remove(key: string, scope = StorageScope.GLOBAL): void {
177+
const storage = (scope === StorageScope.GLOBAL) ? this._globalStorage : this._workspaceStorage;
178+
const storageKey = this.toStorageKey(key, scope);
179+
180+
// Remove
181+
storage.removeItem(storageKey);
182+
}
183+
195184
private toStorageKey(key: string, scope: StorageScope): string {
196185
if (scope === StorageScope.GLOBAL) {
197186
return StorageService.GLOBAL_PREFIX + key.toLowerCase();

src/vs/platform/storage/test/common/storageService.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ suite('Workbench StorageSevice', () => {
2828
});
2929
});
3030

31-
test('Swap Data with undefined default value', () => {
32-
let s = new StorageService(new InMemoryLocalStorage(), null, contextService.getWorkspace().id);
33-
34-
s.swap('Monaco.IDE.Core.Storage.Test.swap', 'foobar', 'barfoo');
35-
assert.strictEqual('foobar', s.get('Monaco.IDE.Core.Storage.Test.swap'));
36-
s.swap('Monaco.IDE.Core.Storage.Test.swap', 'foobar', 'barfoo');
37-
assert.strictEqual('barfoo', s.get('Monaco.IDE.Core.Storage.Test.swap'));
38-
s.swap('Monaco.IDE.Core.Storage.Test.swap', 'foobar', 'barfoo');
39-
assert.strictEqual('foobar', s.get('Monaco.IDE.Core.Storage.Test.swap'));
40-
});
41-
4231
test('Remove Data', () => {
4332
let s = new StorageService(new InMemoryLocalStorage(), null, contextService.getWorkspace().id);
4433
s.store('Monaco.IDE.Core.Storage.Test.remove', 'foobar');

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,6 @@ export class TestStorageService extends EventEmitter implements IStorageService
411411
this.storage.store(key, value, scope);
412412
}
413413

414-
swap(key: string, valueA: any, valueB: any, scope: StorageScope = StorageScope.GLOBAL, defaultValue?: any): void {
415-
this.storage.swap(key, valueA, valueB, scope, defaultValue);
416-
}
417-
418414
remove(key: string, scope: StorageScope = StorageScope.GLOBAL): void {
419415
this.storage.remove(key, scope);
420416
}

0 commit comments

Comments
 (0)